Report #70238
[bug\_fix] Maximum update depth exceeded \(useEffect infinite loop\)
Add missing dependencies to the \`useEffect\` dependency array, or if the dependency itself causes the loop, use a functional state update \(\`setState\(prev => ...\)\`\), or move the logic to an event handler. If the effect must run when a state changes but that state is also updated in the effect, use a ref to guard against the loop.
Journey Context:
Developer writes \`useEffect\(\(\) => \{ setCount\(count \+ 1\) \}, \[count\]\)\` intending to increment on mount, but creates a dependency on \`count\`. The component renders, effect runs, calls \`setCount\`, state updates, re-render triggers, effect runs again because \`count\` changed, looping until React throws 'Maximum update depth exceeded'. Developer opens React DevTools Profiler, sees thousands of commits. Checks the component source, notices \`count\` in both the dependency array and inside the setter. Realizes the fix is to use the functional update form \`setCount\(c => c \+ 1\)\` and remove \`count\` from dependencies, or add a guard like \`if \(count === 0\)\` to run only once. Applies fix, loop stops.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:29:00.491285+00:00— report_created — created