You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Activity
[-]Abort a request[/-][+]Feature request: Abort a request[/+]ryanbrainard commentedon Mar 6, 2017
This came up before (can't find where at the moment), but we decided not to add cancellation functionality because the
fetchAPI 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, thefetchis still performed, but we only keep the response whose request was the started last. Oncefetchhas 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).dmr commentedon Mar 6, 2017
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.
tjokimie commentedon Nov 7, 2018
Fetch now supports
AbortControllerwhich can be used to abort requests, see https://robwise.github.io/blog/cancel-whatwg-fetch-requests-in-react for example.ryanbrainard commentedon Nov 9, 2018
@tjokimie Thanks for finding that. I'll re-open this, but no promises on getting to it any time soon :)