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.
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.
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!
Thank you! I'm not familiar with an AbortController, so can't comment on it.
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.
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 :)