The React documentation for componentWillUnmount()
implies that it is possible to cancel network requests:
Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests, ...
But answers here say it is not possible.
Question being, is it possible or not to cancel a network requests in JS?
For example, if I started a setInterval
to requests using the Fetch API in componentDidMount
, and on some condition I want to stop requests, doing so in componentWillUnmount
per the documentation. How can I cancel all network requests? I'm not talking about calling clearInterval
, which will stop the timer. I want to make sure that any network requests that were started will be canceled in a given condition.