react-adal icon indicating copy to clipboard operation
react-adal copied to clipboard

Cancel request using Axios

Open jordan-kaxig opened this issue 3 years ago • 2 comments

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.

jordan-kaxig avatar May 19 '22 08:05 jordan-kaxig

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();

jordan-kaxig avatar May 19 '22 09:05 jordan-kaxig

Hey can I help you, with the code

ashish-khankari avatar May 03 '23 21:05 ashish-khankari