react-refetch icon indicating copy to clipboard operation
react-refetch copied to clipboard

Feature request: Abort a request

Open dmr opened this issue 7 years ago • 4 comments

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?

dmr avatar Mar 01 '17 13:03 dmr

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).

ryanbrainard avatar Mar 06 '17 05:03 ryanbrainard

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.

dmr avatar Mar 06 '17 08:03 dmr

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 avatar Nov 07 '18 08:11 tjokimie

@tjokimie Thanks for finding that. I'll re-open this, but no promises on getting to it any time soon :)

ryanbrainard avatar Nov 09 '18 05:11 ryanbrainard