DEV Community

Discussion on: Asynchronous Flows...with React Hooks!

Collapse
 
chrisachard profile image
Chris Achard

Nice post! That's a nice way to handle cancellations too (since fetch doesn't handle cancellations normally). The other way I've seen it done with with an AbortController, which is kind of a weird interface though.

thanks!

Collapse
 
silvestricodes profile image
Jonathan Silvestri

Thank you! I'm not familiar with an AbortController, so can't comment on it.

Collapse
 
vyckes profile image
Kevin Pennekamp

Its not really a cancellation, as the fetch will still finish, but this implementation ensures that nothing will happen if the component is not mounted anymore.

Collapse
 
chrisachard profile image
Chris Achard

Right, yes (which is why I was pointing out the AbortController as well) - but yes, good to point out that it doesn't actually cancel the request :)