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.

FormError causes warning 'Cannot update a component from inside the function body of a different component'

See original GitHub issue

When following the tutorial at the section about server-side email validation, when introducing FormError, the console reports the error:

Warning: Cannot update a component from inside the function body of a different component.

This looks to be coming from https://github.com/redwoodjs/redwood/blob/master/packages/web/src/form/form.js#L27

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
colinscapecommented, Apr 9, 2020

@thedavidprice Just to confirm - I was following the tutorial step by step and saw this in my console, so there was no custom code from my side involved - either some tweak to the tutorial or Redwood itself was my feeling. From a quick search about it seems to have been regularly encountered with React 16.3 as @dominicchapman mentioned.

1reaction
dominicchapmancommented, Apr 9, 2020

Hey @thedavidprice I’m also seeing this warning when following the tutorial.

It seems React 16.3.0 may have been over-firing these warnings and has since been fixed in 16.3.1, but looks like react-hook-form would be using 16.3.1 anyway.

Curious, if this could be linked to #162 ? If so, the fix might be as simple as using PascalCase on inputTagProps (i.e. InputTagProps) as described here. Hope this helps.

Digging further, seems it could be a bug on Redwood side. As highlighted in React 16.3.0 release notes:

In the rare case that you intentionally want to change the state of another component as a result of rendering, you can wrap the setState call into useEffect.

So, think the setError call should be wrapped in a useEffect?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update a component from inside the function body of a ...
If you call setState during a render on a different component, you will now see a warning: Warning: Cannot update a component from...
Read more >
Bug: too hard to fix "Cannot update a component from inside ...
Queueing an update for any other component from within the actual rendering body of a function component is illegal. That's what this warning...
Read more >
How to fix the "cannot update a component while rendering a ...
A quick guide to how I solved a confusing React error.
Read more >
Cannot update a component from inside the function body of a ...
JavaScript : React Warning : Cannot update a component from inside the function body of a different component [ Gift : Animated Search...
Read more >
How I fixed 'Cannot update a component from inside the ...
In this short article I'll highlight why Cannot update a component from inside the function body of a different component warning happened ...
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