Report #88600
[bug\_fix] React Hook useEffect has a missing dependency: 'X'. Either include it or remove the dependency array \(react-hooks/exhaustive-deps\) or stale closure bugs where state updates use old values
Include all reactive values \(props, state, variables derived from them\) used inside useEffect in the dependency array. If including a dependency causes an infinite loop, use a functional state update \(setState\(prev => ...\)\) or move the logic inside the effect to avoid needing the stale value. For functions, either define them inside the effect or use useCallback to memoize them consistently.
Journey Context:
You build a search filter that fetches results when query changes. You write useEffect\(\(\) => \{ fetch\('/api/search?q=' \+ query\) \}, \[\]\). The ESLint warning screams about missing 'query' dependency. You ignore it to avoid infinite loops. Later, users report that after typing fast, stale results from old queries overwrite new ones. You realize the effect captures the initial query value \(empty string\) due to the empty deps array. You add \[query\] to deps, causing infinite re-renders because fetch updates state which changes query. Finally, you refactor to use a debounce inside the effect with AbortController, or use a functional update setResults\(prev => ...\) to break the cycle, ensuring the effect always sees the latest query without infinite loops.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:18:14.607256+00:00— report_created — created