fetch-suspense icon indicating copy to clipboard operation
fetch-suspense copied to clipboard

Cancel the fetch if it has not been completed and props changed

Open EECOLOR opened this issue 7 years ago • 4 comments

You can read about the AbortController here: https://developer.mozilla.org/en-US/docs/Web/API/AbortController

EECOLOR avatar Mar 08 '19 23:03 EECOLOR

That may not always be desirable behavior, so I'm unsure about doing it by default.

This is mostly an issue of how does it know which request to cancel. Functional components do not have instances, so I can't say "cancel this Component's last request."

quisido avatar Apr 12 '19 15:04 quisido

I explained poorly. By props I meant arguments to useFetch

EECOLOR avatar Apr 13 '19 11:04 EECOLOR

Oh wait, I understand what you are saying. I see the problem now. You can probably use hooks to help solve that though.

EECOLOR avatar Apr 13 '19 11:04 EECOLOR

@CharlesStover you can useRef to store abort controllers. Maybe take a look at https://github.com/mauricedb/use-abortable-fetch for inspiration. Heck you could even use that hook under the covers.

capaj avatar Aug 05 '19 11:08 capaj