Report #29445
[bug\_fix] React Hook useEffect has a missing dependency: 'someVar'. Either include it or remove the dependency array. Runtime bug: Stale closure where effect uses old variable value.
Add the missing variable to the dependency array. If it causes an infinite loop, use functional state updates \(setState\(prev => ...\)\) or wrap the function in useCallback. Root cause: JavaScript closures capture values at render time; without dependencies, the effect sees stale values from the closure.
Journey Context:
Developer writes useEffect\(\(\) => \{ fetchData\(userId\) \}, \[\]\) to fetch data on mount. Later adds userId as a prop. Effect never re-runs when userId changes, showing stale data from first user. ESLint warns about missing dependency. Developer ignores warning to avoid 'dependency hell'. Bug appears in production where clicking 'Next User' doesn't update the feed. Developer adds userId to deps, but now gets infinite loop because fetchData updates state that causes re-render, triggering effect again. Realizes need to use functional update form for setState or wrap fetchData in useCallback with its own deps. Finally fixes by adding userId to effect deps and using useCallback for the fetch function.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:48:55.042991+00:00— report_created — created