Report #102381
[bug\_fix] useEffect hook missing dependency
Add the missing dependency to the dependency array, or move the value inside the effect if it should not be a dependency. If the linter is wrong because the value is a ref or is defined inside the effect, use eslint-disable-next-line react-hooks/exhaustive-deps and document why. Avoid lying about dependencies; stale closures cause subtle bugs.
Journey Context:
You write a search input that fetches results in useEffect whenever the query changes. After typing fast, results for old queries overwrite newer ones. You check the dependency array and realize you only listed \[query\] but the effect also reads currentPage from state. When currentPage changes, the effect doesn't rerun because you forgot it. You add currentPage and a cleanup AbortController to cancel in-flight requests. The linter warning "React Hook useEffect has a missing dependency" was the clue. You then notice an object dependency that changes identity on every render, causing infinite refetches; you memoize it with useMemo or move construction into the effect. The fix works because the dependency array is a contract: React only re-runs the effect when listed values change, so omitting a used value causes stale data and including an unstable value causes extra runs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T04:46:52.813899+00:00— report_created — created