Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

cancel an HTTP fetch() request at useFetch hooks #127

Open
dzakki opened this issue Oct 8, 2021 · 1 comment
Open

cancel an HTTP fetch() request at useFetch hooks #127

dzakki opened this issue Oct 8, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@dzakki
Copy link

dzakki commented Oct 8, 2021

when we are doing http request and not yet completed the request, but we unmount the hooks or the component, then we will get error, because the http request still running and when completed then we do change state setResponse(json); or setError(error);.

Warning: 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 the componentWillUnmount
method.

Solution
we should cancel the subscriptions of fetching, when the component will unmount.

reference to fix:
https://stackoverflow.com/questions/31061838/how-do-i-cancel-an-http-fetch-request
https://stackoverflow.com/questions/53949393/cant-perform-a-react-state-update-on-an-unmounted-component

@30secondsofcode 30secondsofcode added the bug Something isn't working label Oct 24, 2021
@Chalarangelo
Copy link
Owner

Noted, we're already working on this! 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants