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

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

@dzakki

Description

@dzakki

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions