BetterTyped / hyper-fetch

⚡ Fetching and realtime data exchange framework.
https://hyperfetch.bettertyped.com/
Apache License 2.0
1.02k stars 27 forks source link

useFetch: Disabling or stop refreshing a request is not possible once refresh = true has been set #67

Closed stefanullinger closed 1 year ago

stefanullinger commented 1 year ago

Hello again,

in my current project the user clicks on a button, which starts some long running backend process via an API call. Now I wanted to make use of the refreshing feature mentioned here, to get some status update from the API:

Once the backend task finishes, the API will respond with some special data, which I wanted to use to stop polling. But I am unable to stop refreshing once it has been started. I tried setting refresh to false, and also tried setting disabled to true.

I think refresh here (https://github.com/BetterTyped/hyper-fetch/blob/ec9542266ad900560404464ee8443cea7ac1ffee/packages/react/src/hooks/use-fetch/use-fetch.hooks.ts#L102C10-L102C17) has not access to latest value.

Is this a bug? Or am I doing something wrong?

I have created an example here: https://codesandbox.io/s/hyper-fetch-stop-refresh-fzgglc?file=/src/App.tsx Click the button to start polling for updates. After 5 seconds, polling should stop, but it does not. You can see that in the network tab of the dev tools.

Best Stefan

prc5 commented 1 year ago

Hey @stefanullinger thanks again for helping us! I will fix it in a minute 👍🏻

stefanullinger commented 1 year ago

Thank you!