react-refetch
react-refetch copied to clipboard
Feature request: Abort a request
Is there a way to abort a request that was started by refetch?
We build a search component that queries "live" when the user enters characters. Is there a way to stop the first request if the user entered something else?
This came up before (can't find where at the moment), but we decided not to add cancellation functionality because the fetch
API didn't have something for cancelling and looks like it still doesn't, so we'd really just end up only ignoring responses, which is already in effect what happens when we compare timestamps of the previous state. In other words, the fetch
is still performed, but we only keep the response whose request was the started last. Once fetch
has a way to cancel, I'd be open to exploring this more, but until then, what we have now is probably sufficient (please re-open if you think otherwise).
Thank you for the response. I unterstand your argument and think that it is a wise choice to wait for fetch.
Unfortunately I still have the use case to implement so maybe I'll explore other options.
Fetch now supports AbortController
which can be used to abort requests, see https://robwise.github.io/blog/cancel-whatwg-fetch-requests-in-react for example.
@tjokimie Thanks for finding that. I'll re-open this, but no promises on getting to it any time soon :)