Report #103777
[bug\_fix] 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 https://reactjs.org/link/setstate-in-render
Move the setState call out of the render phase. Compute derived state directly during render without calling setState, or use useEffect if the update must happen after paint. If a child must notify a parent, pass an event handler or use a state manager instead of calling setState during render.
Journey Context:
A parent component passes a setter to a child, and the child calls setParentState during its render to synchronize some derived value. React prints the warning that a component is being updated while a different component is rendering. The warning appears because setState during render is a side effect in the render phase, which is not allowed: it can cause infinite loops, torn renders, and nondeterministic behavior. The developer first tries wrapping the call in useEffect, which fixes the warning but feels awkward. The better fix depends on intent: if the value is derived, compute it in the parent and pass it down as props; if the child genuinely produces an event, pass an onChange callback and call the setter there. The React docs explicitly call this pattern out because it breaks the guarantee that render is pure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T04:41:27.394657+00:00— report_created — created