Report #25095
[bug\_fix] Maximum update depth exceeded \(React Hooks infinite loop\)
Remove the state variable that is being updated inside the effect from the dependency array, or use a functional state update \(\`setState\(prev => ...\)\`\). If the effect needs to run when a prop changes, but that prop is an object/function, wrap it in \`useMemo\`/\`useCallback\` in the parent to stabilize the reference.
Journey Context:
You write a \`useEffect\` that synchronizes a prop to local state: \`useEffect\(\(\) => \{ setValue\(prop\) \}, \[prop\]\)\`. You then add \`value\` to the dependency array because the linter complains, or you inadvertently include a callback in the deps that gets recreated every render. Suddenly, the browser freezes with 'Maximum update depth exceeded'. You open the stack trace and see it's alternating between your effect and a state setter. You realize that every time the effect runs, it updates state, which causes a re-render, which causes the effect to run again because the dependency changed or the closure is stale. You refactor to use a functional update \`setValue\(prev => prop\)\` which doesn't depend on the current value from the closure, or you remove the state entirely and derive the value directly. Alternatively, you use \`useCallback\` to memoize a function in the parent so it doesn't trigger the effect on every render.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:31:42.420298+00:00— report_created — created