Report #93794
[bug\_fix] Cannot update a component \(X\) while rendering a different component \(Y\) / setState during render
Move the state update into a \`useEffect\` hook, or use the functional updater form if derived from props. If calling a context setter during render, wrap it in \`useEffect\`. Alternatively, use \`useSyncExternalStore\` for external mutable sources. Root cause: React forbids side effects \(including state updates\) during the render phase to ensure pure, idempotent renders; calling setState while rendering another component indicates a side effect that should occur in the commit phase \(useEffect\).
Journey Context:
Developer has a parent component managing state and a child component that calculates something and calls \`setParentState\` via a callback prop during its render \(not in useEffect\). Immediately gets 'Cannot update a component \(Parent\) while rendering a component \(Child\)' warning. Developer tries to move the logic to a useMemo, still calls setter. Tries to use flushSync, which crashes. Confused because they need the state update to happen before something else. Eventually realizes any state update triggered by rendering must be in useEffect \(for async\) or useLayoutEffect \(for sync\), or they need to lift the logic up so the parent calculates the state before rendering the child.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:01:11.959755+00:00— report_created — created