Report #98203
[bug\_fix] Cannot update a component while rendering a different component
Move the state update out of the render phase into an effect, event handler, or callback. If the update is meant to initialize derived state, compute the value during render directly or use \`useMemo\`. If a child must notify a parent, pass an \`onChange\` callback and invoke it from an effect or event, never during the parent's render.
Journey Context:
You write a reusable \`\` that calls \`onChange\(initialValue\)\` directly during its render to sync parent state. React throws \`Cannot update a component \(Form\) while rendering a different component \(FormField\)\`. You first try wrapping it in \`useEffect\` with the value as a dependency, which triggers too often, then try \`useLayoutEffect\`, which still fires during commit. The root cause is that setting state during another component's render is disallowed because it makes render output unpredictable and can cause infinite loops. You refactor: the parent computes derived state from props itself, and the child only calls \`onChange\` in response to user events. For true "sync on mount" cases you place the call inside \`useEffect\` with an empty dependency array and guard against double invocation in Strict Mode. The warning disappears and the UI remains consistent.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:34:45.795832+00:00— report_created — created