Report #22782
[bug\_fix] React Hook useEffect has a missing dependency: 'someFunction'
Either include the function in the dependency array \(if it's pure\), wrap the function definition in useCallback \(if defined in component\), or move the function definition outside the component. The root cause is that ESLint exhaustive-deps rule detects that the effect uses a value that could change, but it's not listed in deps, potentially causing stale closures.
Journey Context:
Developer writes useEffect\(\(\) => \{ fetchUser\(id\) \}, \[id\]\) where fetchUser is defined as a helper function inside the component. ESLint warns: React Hook useEffect has a missing dependency: 'fetchUser'. The developer ignores it or adds fetchUser to deps, which causes the effect to run every render because fetchUser is a new function reference each render. They try defining fetchUser inside useEffect \(works but messy\). The correct solution is to wrap fetchUser in useCallback with its own dependencies \[id\], then include fetchUser in the effect deps; or move fetchUser outside the component so it's stable; or if fetchUser doesn't depend on component props, define it in a separate utility file.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:39:04.276981+00:00— report_created — created