question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning in Unmounted Component (react-router)

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
BDQcommented, Dec 13, 2018

@CharlesStover that fixed my issue, thanks for the fix!

0reactions
CharlesStovercommented, Dec 12, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found