Warning in Unmounted Component (react-router)
See original GitHub issueHi there, I currently have a Login Component, and based on the server’s response I will call (react-router-dom
) <Redirect to='/dashboard' />
if the server responds with affirmation the user has a valid session cookie already. However, I get this warning inside my component:
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 a useEffect cleanup function.
in Login (created by LoginBox)
in div (created by Card)
in div (created by Card)
in Card (created by LoginBox)
in LoginBox (created by Route)
To clarify, the setState is already done by the time the redirect is called:
// Hooks, Handlers, etc.
...
if (authorized) {
return <Redirect to='/dashboard' />
}
// else, Display Login Component
...
From the Warning, I get a hint that something should be cleaned up? Not sure if this is related to https://github.com/CharlesStover/reactn/issues/5.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Can't perform a React state update on an unmounted ...
Warning : Can't perform a React state update on an unmounted component. Solution. You can declare let isMounted = true inside useEffect ,...
Read more >Avoid React state update warnings on unmounted components
React raising a warning when you try to perform a state update on an unmounted component. React setState is used to update the...
Read more >Can't perform a react state update on an unmounted component
To solve the "Warning: Can't perform a React state update on an unmounted component", declare an isMounted boolean in your useEffect hook that...
Read more >How to handle React State Update on Unmounted ...
Learn how to handle the React State Update warning on an Unmounted Component by managing the state properly for async operations.
Read more >Prevent React setState on unmounted Component
Warning : Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@CharlesStover that fixed my issue, thanks for the fix!
I’ve got what I believe is a fix for this situation. The problem is when a parent and child both listen to the same property, the parent re-rendering causes the child to unmount (in addition to itself unmounting) while the child is still queued to re-render.
I’ve changed it so that unmounting a component also removes property listeners that are already queued to occur, and the error seems to have disappeared in the above examples.
Let me know if you still encounter this issue. My commit will close this Issue, so feel free to make a new one. This will be released in a few moments as ReactN 0.1.8.