use-http icon indicating copy to clipboard operation
use-http copied to clipboard

Expose `responseID`

Open QingWei-Li opened this issue 4 years ago • 7 comments

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.

QingWei-Li avatar Mar 03 '21 04:03 QingWei-Li

Thanks! What would the syntax look like.

iamthesiz avatar Mar 03 '21 05:03 iamthesiz

Such as

const { responseID } = useFetch()

QingWei-Li avatar Mar 03 '21 05:03 QingWei-Li

maybe just add it to the response

const { response } = useFetch()
response.id

iamthesiz avatar Mar 03 '21 18:03 iamthesiz

This is not an property of the native Response. Adding additional properties may not be appropriate.

QingWei-Li avatar Mar 04 '21 01:03 QingWei-Li

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

iamthesiz avatar Mar 04 '21 07:03 iamthesiz

You are right. response.id is better.

QingWei-Li avatar Mar 04 '21 08:03 QingWei-Li

@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?

SyFlo avatar Jan 02 '23 13:01 SyFlo