Skip to content

Warning: React Hook useEffect has a missing dependency

Error message

                React Hook useEffect has a missing dependency: 'value'
              

Quick summary

Your useEffect references a variable that isn't in its dependency array, which can cause the effect to use stale values.

Why this happens

  • Used a prop or state variable inside useEffect but didn't add it to the deps array

  • Used a function defined in the component without adding it to deps

  • Intentionally omitted a dependency to run the effect less often

Minimal example

✗ Broken code
useEffect(() => {
  document.title = `Count: ${count}`;
}, []); // Missing `count`!
✓ Fixed code
useEffect(() => {
  document.title = `Count: ${count}`;
}, [count]);

The effect uses count but it wasn't in the deps array. Adding it ensures the effect re-runs with the current value when count changes.

How to diagnose

  • Check every variable used inside useEffect against the dependency array

  • Use the exhaustive-deps ESLint rule to auto-detect

  • Look for stale closure bugs (effect uses old values)

How to fix

  • Add the missing variable to the dependency array

  • If the variable is a function, wrap it in useCallback to stabilize it

  • If intentionally omitting, add an eslint-disable comment with a reason

How to prevent

  • Enable eslint-plugin-react-hooks exhaustive-deps rule

  • Always list every external value used in the effect

Related Resources

Related Glossary

Related Lessons

← Back to language