Having react & redux application that using asynchronous calls via Axios, I need to cancel such request that are still in progress once the user navigate to other page or anything else. Being new to react I came up with an idea to keep the axios cancelToken in redux state and cancel it in componentWillUnmount()
of the react component.
example:
componentWillUnmount() {
const (isLoading, cancelToken} = this.props;
if (isLoading) {
cancelToken.cancel("Abort request");
}
}
Are there better patterns or solution to this?
EDIT: Async call is being fired in redux-thunk i.e. action