Report #97729
[bug\_fix] React Hook useEffect has a missing dependency: '...'. Either include it or remove the dependency array
Include every value used inside the effect that can change over time in the dependency array. If that causes infinite loops, move state derivation outside the effect, use a functional state update, or memoize the dependency with useMemo/useCallback. If the value truly never changes, declare it outside the component or use a ref.
Journey Context:
I wrote an effect that fetched user data whenever userId changed. It worked for the first user, but switching users kept showing stale data or ran repeatedly in a loop. ESLint warned about a missing dependency. I tried disabling the rule, which silenced the warning but left the bug. The real issue was my effect referenced filters derived from props but only listed userId in deps. When filters changed, React did not re-run the effect. Adding all used values to the dependency array fixed staleness. I then had to refactor a derived filters object into useMemo to stop the effect from firing every render because a new object was created each time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:35:59.213142+00:00— report_created — created