Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel request using Axios #126

Open
jordan-kaxig opened this issue May 19, 2022 · 2 comments
Open

Cancel request using Axios #126

jordan-kaxig opened this issue May 19, 2022 · 2 comments

Comments

@jordan-kaxig
Copy link

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
Copy link
Author

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

@ashish-khankari
Copy link

Hey can I help you, with the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants