Report #98687
[bug\_fix] React warning 'React Hook useEffect has missing dependencies' or a stale-closure bug where an effect does not see the latest prop/state, or an infinite re-render loop.
Declare every reactive value read inside the effect \(props, state, and variables/functions declared in the component body\) in the dependency array. If a dependency changes too often, reduce it: use functional state updates \(setCount\(c => c \+ 1\)\) for state the effect updates, move objects/functions created during render inside the effect, or memoize them with useMemo/useCallback only when necessary. Do not silence exhaustive-deps without proving the value is non-reactive.
Journey Context:
Built a dashboard filter. The component fetched data in useEffect using filter and sort props, but I left them out of the deps to 'avoid extra requests'. When the user changed the filter, the network call still used the old value, producing stale results. The ESLint rule react-hooks/exhaustive-deps underlined the array; at first I added // eslint-disable-next-line. After re-reading React's useEffect reference, I understood that the closure captures values from the render when the effect ran, so omitting deps is a stale-closure trap. I listed filter, sort, and page as dependencies, then moved the derived options object inside the effect so it stopped being a dependency. The fetches now stay in sync with the UI.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:36:32.180160+00:00— report_created — created