Skip to content
Advertisement

Cannot update a component while rendering a different component warning

I am getting this warning in react:

JavaScript

I went to the locations indicated in the stack trace and removed all setstates but the warning still persists. Is it possible this could occur from redux dispatch?

my code:

register.js

JavaScript

function which triggers the warning in my registerForm component called by register.js

JavaScript

Stacktrace:

Stacktrace

Advertisement

Answer

I fixed this issue by removing the dispatch from the register components render method to the componentwillunmount method. This is because I wanted this logic to occur right before redirecting to the login page. In general it’s best practice to put all your logic outside the render method so my code was just poorly written before. Hope this helps anyone else in future 🙂

My refactored register component:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement