use-http
use-http copied to clipboard
Expose `responseID`
Nice work! Very useful library.
I want to control the cache, but the id is unknown. I hope the responseID can be exposed.
https://github.com/ava/use-http/blob/c96145651c109e1241343982ae72cd8ad49189d4/src/doFetchArgs.ts#L95-L105
I can contribute code if needed.
Thanks! What would the syntax look like.
Such as
const { responseID } = useFetch()
maybe just add it to the response
const { response } = useFetch()
response.id
This is not an property of the native Response. Adding additional properties may not be appropriate.
Let me think about it. The benefit of having it be a part of response is it has the ability to not be stale in functions defined within the app. For example
const App = () => {
const { responseID, response, get } = useFetch()
const onClick = () => {
const x = await get('/x')
console.log('responseID', responseId) // <- would be stale showing data from previous request
console.log('response.id', response.id) // <- would be current, showing this* request's response ID
}
return (
<button onClick={handleClick}>Click Me!</button>
)
}
Open to more discussions though
You are right. response.id is better.
@alex-cory @QingWei-Li this issue has been open for almost two years now. is the response id now exposed and if so, how exactly can it be accessed?