Report #6730
[bug\_fix] Maximum update depth exceeded or infinite loop in useEffect
Use useMemo for object/array dependencies or move the object definition outside the component. Root cause: JavaScript object/array equality is by reference; inline definitions create new references every render, triggering the effect, which updates state, causing re-render and new reference.
Journey Context:
Developer writes a data fetching hook: \`useEffect\(\(\) => \{ fetchData\(filters\); \}, \[\{ status: 'active' \}\]\)\`. Immediately on component mount, the browser tab freezes and console shows "Maximum update depth exceeded". They open React DevTools Profiler and see a rapid loop of renders. They realize the dependency array contains an inline object literal. On every render, \`\{ status: 'active' \}\` creates a new object in memory. React's dependency comparison sees old object \!== new object, so it runs the effect. The effect calls setState \(via fetchData\), triggering a re-render, creating another new object, and looping infinitely. They fix it by wrapping the object in useMemo or moving it outside the component to maintain stable reference.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:47:43.616939+00:00— report_created — created