How to fix React Hook useEffect has missing dependencies: 'count'. Either include it or remove the dependency array. in React

ReactINTERMEDIATEMEDIUMUpdated Dec 8, 2025· 119 views

This ESLint warning occurs when your useEffect hook references variables, props, or state that are not included in its dependency array. When dependencies are missing, your effect may run with stale values or fail to re-run when those values change, leading to bugs and unexpected behavior.

Quick fix

Fixes React Hook useEffect has missing dependencies: 'count'. Either include it or remove the dependency array.

function MyComponent({ userId, onUpdate }) {
  const [data, setData] = useState(null);

  useEffect(() => {
    // userId, onUpdate, and fetchData are dependencies
    fetchData(userId).then(result => {
      setData(result);
      onUpdate(result);
    });
  }, []); // ❌ Missing dependencies!
}
  1. Identify all dependencies used inside the effect
  2. Add all identified dependencies to the array
  3. Move stable calculations inside the effect
  4. Wrap functions with useCallback for stability
react — error
function MyComponent({ userId, onUpdate }) {
const [data, setData] = useState(null);
useEffect(() => {
// userId, onUpdate, and fetchData are dependencies
fetchData(userId).then(result => {
setData(result);
onUpdate(result);
});
}, []); // ❌ Missing dependencies!
}
React Hook useEffect has missing dependencies: 'count'. Either include it or remove the dependency array.

What this error means

The "React Hook useEffect has a missing dependency" warning is triggered by ESLint's react-hooks/exhaustive-deps rule, not by React itself. This rule analyzes your useEffect hooks and compares the variables, props, state, and functions referenced inside the effect against the dependency array you provided. When you use a value inside useEffect that can change over time (like props, state, or functions defined in the component), React needs to know about it through the dependency array. This tells React when to re-run the effect. If you omit a dependency, the effect will continue using the old value from when it first ran, even after the value has changed. This can lead to subtle bugs where your UI doesn't update correctly, API calls use stale parameters, or event handlers reference old state. The ESLint rule exists to catch these issues before they become runtime bugs.

Typical symptoms

  • Yellow or orange ESLint warning in your code editor under the useEffect hook
  • Effect continues using old/stale values even after props or state have changed
  • Component doesn't re-render or update when expected after state changes
  • API calls or side effects run with outdated parameters
  • Event handlers or callbacks inside useEffect reference old state values
  • Console shows the specific warning message naming which dependencies are missing
  • Build warnings during CI/CD pipeline execution with ESLint configured

Common causes

  1. Referencing component props inside useEffect without including them in the dependency array
  2. Using state variables (from useState) inside the effect but not listing them as dependencies
  3. Calling functions defined in the component scope that reference props or state
  4. Accessing object properties or array elements that can change between renders
  5. Using values from context (useContext) without including the context value in dependencies
  6. Referencing variables from parent component scope that aren't stable across renders
  7. Destructuring props or state before useEffect and only including partial dependencies
  8. Intentionally using an empty dependency array [] to run effect only once, but the effect uses dynamic values

How to fix "React Hook useEffect has missing dependencies: 'count'. Either include it or remove the dependency array."

1Identify all dependencies used inside the effect

Review your useEffect code and list every variable that comes from outside the effect scope. This includes props, state, context values, and functions.

jsx
function MyComponent({ userId, onUpdate }) {
  const [data, setData] = useState(null);

  useEffect(() => {
    // userId, onUpdate, and fetchData are dependencies
    fetchData(userId).then(result => {
      setData(result);
      onUpdate(result);
    });
  }, []); // ❌ Missing dependencies!
}

Look for variables that can change between renders. Constants defined outside the component are safe to omit.

2Add all identified dependencies to the array

Include every dependency in the array. This is the most straightforward fix.

jsx
function MyComponent({ userId, onUpdate }) {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetchData(userId).then(result => {
      setData(result);
      onUpdate(result);
    });
  }, [userId, onUpdate]); // ✅ Dependencies added
}

The effect will now re-run whenever userId or onUpdate changes.

3Move stable calculations inside the effect

If you're using derived values or transformations, move them inside useEffect to reduce dependencies.

jsx
// Before: external calculation creates dependency
function MyComponent({ user }) {
  const userName = user.firstName + ' ' + user.lastName;

  useEffect(() => {
    console.log(userName);
  }, [userName]); // userName recreated every render
}

// After: calculation inside effect
function MyComponent({ user }) {
  useEffect(() => {
    const userName = user.firstName + ' ' + user.lastName;
    console.log(userName);
  }, [user]); // Only depend on user object
}
4Wrap functions with useCallback for stability

If your effect depends on a function, wrap it with useCallback to prevent unnecessary re-runs.

jsx
function MyComponent({ userId }) {
  const [data, setData] = useState(null);

  // Without useCallback: function recreated every render
  const loadData = useCallback(async () => {
    const result = await fetchData(userId);
    setData(result);
  }, [userId]); // loadData only changes when userId changes

  useEffect(() => {
    loadData();
  }, [loadData]); // ✅ Safe dependency
}

This ensures the function reference stays stable unless its dependencies change.

5Move constant values outside the component

If a value never changes, move it outside the component to prove it's not reactive.

jsx
// Move constants outside
const API_ENDPOINT = 'https://api.example.com';
const DEFAULT_OPTIONS = { timeout: 5000 };

function MyComponent({ userId }) {
  useEffect(() => {
    fetch(`${API_ENDPOINT}/users/${userId}`, DEFAULT_OPTIONS);
  }, [userId]); // Only userId is a dependency
}

Constants defined outside the component don't need to be in the dependency array.

6Use functional setState updates for state dependencies

When updating state based on previous state, use the functional form to remove the state dependency.

jsx
function Counter({ increment }) {
  const [count, setCount] = useState(0);

  // Before: depends on count
  useEffect(() => {
    const timer = setInterval(() => {
      setCount(count + increment);
    }, 1000);
    return () => clearInterval(timer);
  }, [count, increment]); // Resets timer every second!

  // After: no count dependency needed
  useEffect(() => {
    const timer = setInterval(() => {
      setCount(prevCount => prevCount + increment);
    }, 1000);
    return () => clearInterval(timer);
  }, [increment]); // ✅ Only increment is needed
}
7Verify the warning is resolved

Check your code editor and build output to confirm the ESLint warning is gone.

bash
# Run ESLint to check for warnings
npm run lint

# Or build the project
npm run build

The warning should no longer appear. Test that your component behaves correctly by changing the dependency values and verifying the effect re-runs as expected.

Advanced notes

When to disable the rule: In rare cases, you may intentionally want an effect to run only once with specific values. Before disabling, ensure you understand the risks:

jsx
useEffect(() => {
  // I want this to run only on mount, using initial props
  logAnalytics(initialUserId);
  // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Understanding effect timing: Effects with different dependencies run at different times. An empty array [] means "run once after mount", while [value] means "run after mount and whenever value changes".

Objects and arrays as dependencies: Comparing objects and arrays by reference can cause infinite loops. Use useMemo to stabilize them:

jsx
const config = useMemo(() => ({
  apiKey: key,
  timeout: 3000
}), [key]);

useEffect(() => {
  initializeAPI(config);
}, [config]);

ESLint configuration: The exhaustive-deps rule is part of eslint-plugin-react-hooks. Ensure you have it installed and configured in .eslintrc:

json
{
  "plugins": ["react-hooks"],
  "rules": {
    "react-hooks/exhaustive-deps": "warn"
  }
}

React 18+ considerations: With concurrent features, stale closures become even more problematic. Always include dependencies to ensure your effects work correctly with concurrent rendering and automatic batching.

Frequently asked questions

What does "React Hook useEffect has missing dependencies: 'count'. Either include" mean?
The "React Hook useEffect has a missing dependency" warning is triggered by ESLint's react-hooks/exhaustive-deps rule, not by React itself. This rule analyzes your useEffect hooks and compares the variables, props, state, and functions referenced inside the effect against the dependency array you provided. When you use a value inside useEffect that can change over time (like props, state, or functions defined in the component), React needs to know about it through the dependency array.
How do I fix "React Hook useEffect has missing dependencies: 'count'. Either include"?
This ESLint warning occurs when your useEffect hook references variables, props, or state that are not included in its dependency array. When dependencies are missing, your effect may run with stale values or fail to re-run when those values change, leading to bugs and unexpected behavior.
What causes "React Hook useEffect has missing dependencies: 'count'. Either include"?
Referencing component props inside useEffect without including them in the dependency array Using state variables (from useState) inside the effect but not listing them as dependencies Calling functions defined in the component scope that reference props or state
Is the "React Hook useEffect has missing dependencies: 'count'. Either include" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading