Possible cause and solution for this warning

Viewed 8391

Warning : Cannot update a component (X) while rendering a different component (Y). To locate the bad setState() call inside Y, follow the stack trace as described in :

1 Answers

There are suggestions on this document. It looks like the same warning. doc door

It is supported to call setState during render, but only for the same component. If you call setState during a render on a different component, you will now see a warning:

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

This warning will help you find application bugs caused by unintentional state changes. 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.

Related