Report #48046
[bug\_fix] React Hook useEffect has a missing dependency: 'someVariable'. Either include it or remove the dependency array
Add the missing variable to the dependency array. If it causes an infinite loop because the variable is an object or function, wrap that variable in useMemo or useCallback to stabilize its reference, or move the function definition inside the useEffect.
Journey Context:
Developer writes a useEffect to fetch data when a prop ID changes, including ID in the dependency array but forgetting to include the fetch function or a navigate function used inside. ESLint flags the exhaustive-deps warning. Developer ignores it or adds eslint-disable-next-line react-hooks/exhaustive-deps. Months later, a bug appears where the effect uses stale data from a closure because the effect never re-ran when a dependency changed. After painful debugging, developer learns that the dependency array must include all reactive values used inside. They refactor to use useCallback for the fetch function to prevent infinite loops while satisfying the lint rule.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:07:51.279725+00:00— report_created — created