Report #41484
[bug\_fix] Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate
Break the infinite loop by removing the dependency that changes every render from the useEffect dependency array. If the effect sets state based on previous state, use the functional update form: \`setCount\(c => c \+ 1\)\` and remove the dependency entirely. If the effect must respond to prop changes, ensure the dependency is a primitive value or use useMemo to stabilize object references.
Journey Context:
A junior developer writes a countdown timer in a Next.js page: \`useEffect\(\(\) => \{ setCount\(count - 1\) \}, \[count\]\)\`. The moment the component mounts, the browser tab freezes and the console spams 'Maximum update depth exceeded'. The developer opens React DevTools Profiler and sees a waterfall of renders, each triggering the next. They try removing the dependency array entirely to silence ESLint, but this triggers the effect on every render anyway. Desperate, they search StackOverflow and discover the concept of 'stale closures' and 'functional updates'. They refactor to \`setCount\(prev => prev - 1\)\` and remove \`count\` from the dependencies, breaking the infinite chain because the effect no longer needs to re-run when count changes—it schedules the next tick independently.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:06:14.070925+00:00— report_created — created