Memory leak when fetching data in useEffect with async/await #142736
Replies: 2 comments
-
This is a common issue when dealing with asynchronous operations in React components. The problem occurs when the component unmounts before the fetch operation completes. Here's how to fix it using an abort controller:
This enhanced version includes:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Please see this comment for reference to why this discussion was closed and locked. Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Body
I'm building a React component that fetches data from an API, but I'm getting a warning about memory leaks when navigating away from the component before the fetch completes. Here's my current implementation:
The console shows this warning:
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.
How can I properly handle cleanup to prevent these memory leaks?
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions