Report #87472
[bug\_fix] Maximum update depth exceeded in useEffect due to object dependency
Remove the object/array from the dependency array and use primitive values \(strings/numbers\) instead, or wrap the object in \`useMemo\` to maintain referential equality across renders. If the effect updates state that triggers the effect, use a functional state update or a ref to break the cycle.
Journey Context:
A developer writes a \`useEffect\` that fetches user data based on a \`filters\` object prop containing \`status\` and \`sort\`. They add \`filters\` to the dependency array: \`useEffect\(\(\) => \{ fetchData\(filters\) \}, \[filters\]\)\`. The parent component recreates the \`filters\` object on every render with \`\{ status: 'active', sort: 'name' \}\`. Immediately, the browser tab freezes or shows "Maximum update depth exceeded." The developer opens React DevTools Profiler and sees an infinite loop: render -> effect runs -> sets state -> triggers re-render -> effect runs again. They try removing \`filters\` from deps, but ESLint warns. They realize the object identity changes every render. They refactor to pass primitive dependencies: \`\[filters.status, filters.sort\]\`, or wrap \`filters\` in \`useMemo\` in the parent. The loop stops because the effect only runs when the primitive values actually change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:24:36.329102+00:00— report_created — created