react-adal
react-adal copied to clipboard
Cancel request using Axios
I need this to avoid the react error "Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function."
I know about the "cancel token" as described in this Medium article.
But how to implement this with react-adal is not clear.
I think I've managed by passing a using a AbortController like this:
const controller = useMemo(() => new AbortController(), []);
Then I can pass a signal in the options object like so:
const result = await adalConfig.adalApiFetch("(yourPath", {
method: "GET",
signal: controller.signal,
});
And then I can abort like this:
controller.abort();
Hey can I help you, with the code