Report #60787
[bug\_fix] React Hook useEffect has a missing dependency: 'someVar'. Either include it or remove the dependency array
Add the missing dependency to the array, but if it causes an infinite loop, memoize the dependency with useMemo/useCallback to stabilize its reference, or move the logic inside the effect.
Journey Context:
Developer has const \[count, setCount\] = useState\(0\); and const multiplier = 2;. They write useEffect\(\(\) => \{ console.log\(count \* multiplier\); \}, \[count\]\);. The ESLint rule react-hooks/exhaustive-deps warns about the missing multiplier dependency. Developer ignores it. Later, when the multiplier value changes \(perhaps passed as a prop\), the effect still logs the old multiplier value due to a stale closure. Developer tries adding multiplier to the dependency array, but now the effect runs every time the component re-renders \(if multiplier is a new object each time\), potentially causing an infinite loop if setState is called inside. They realize they must include all reactive dependencies, but if that breaks stability, they need to wrap the dependency in useMemo \(if it's a value\) or useCallback \(if it's a function\) to maintain referential equality across renders.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:30:55.927485+00:00— report_created — created