Your both dispatch are called after first render so even before your second render value is 0 so your second useEffect won't be able detect change as there is no change.

Let's see what is happening in your render method

First Render:

a = 0

first useEffect: dispatch({ a : 1 })

second useEffect: dispatch({ a : 0 })

so now in your redux store a is 0.

Second Render

a = 0

first useEffect: doesn't run as there is no dependency

second useEffect: doesn't run as a hasn't changed.

Answer from Amit Chauhan on Stack Overflow
🌐
React
react.dev › reference › react › useEffect
useEffect – React
To fix this, remove unnecessary object and function dependencies. You can also extract state updates and non-reactive logic outside of your Effect. If your Effect wasn’t caused by an interaction (like a click), React will generally let the ...
🌐
GitHub
github.com › facebook › react › issues › 24042
Bug: useEffect closure not called when dependencies changed · Issue #24042 · facebook/react
March 8, 2022 - In the reproducing example, the useEffect closure is not called for the updated value. Further changes correctly call the closure though. The useEffect closure should be called in the reproducing example. We see that the component renders with the updated value, so the useEffect dependencies definitely changed.
Author   fabb
Discussions

useEffect not working when dependency value changed
use proper selector and change order of useEffects - it should work as expected (in some sense - react for redux store changes, not amount of changes) More on stackoverflow.com
🌐 stackoverflow.com
reactjs - How to fix missing dependency warning when using useEffect React Hook - Stack Overflow
Bring the best of human thought ... at your work. Explore Stack Internal ... With React 16.8.6 (it was good on previous version 16.8.3), I get this error when I attempt to prevent an infinite loop on a fetch request: ./src/components/BusinessesList.js Line 51: React Hook useEffect has a missing dependency: ... More on stackoverflow.com
🌐 stackoverflow.com
Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error
Someone described it as not "ergonomic". And the same issue will continue to arise in the project this originates from. IMO in 2023 the React linter causes a conflict against what is commonly taught and what for my practical purposes has both worked and caused no issues. The clean up useEffect has a different behavior when given no dependency ... More on github.com
🌐 github.com
11
September 4, 2023
What is the purpose of useEffect without a dependency array?

I'm guessing the only difference is that useEffect will guarantee that it will always run after the render, it also makes sure that every other component that needs to re-render will finish rendering before running the effect.

Though I can't really think of a good use case for this.

More on reddit.com
🌐 r/reactjs
66
118
March 3, 2022
🌐
Epic React
epicreact.dev › why-you-shouldnt-put-refs-in-a-dependency-array
Why you shouldn't put refs in a dependency array | Epic React by Kent C. Dodds
July 9, 2024 - So it actually makes no difference whether you include it or not and I guess the authors of the lint rule decided to not bother you about something that doesn't matter. Good call. But here's an interesting case. What about a custom hook that accepts a ref? ... React Hook React.useEffect has a missing dependency: 'cbRef'.
🌐
freeCodeCamp
freecodecamp.org › news › most-common-react-useeffect-problems-and-how-to-fix-them
React.useEffect Hook – Common Problems and How to Fix Them
October 14, 2021 - Nice! Everything looks and works as expected. But wait... what is this? ... React Hook useEffect has a missing dependency: 'user'. Either include it or remove the dependency array.
🌐
Kinsta®
kinsta.com › home › resource center › blog › react errors › how to fix the “react hook useeffect has a missing dependency” error
How To Fix the “React Hook useEffect Has a Missing Dependency” Error
October 1, 2025 - Similarly, when working with functions, you can use the useCallback hook. The “React Hook useEffect has a missing dependency” error is an ESLint warning error — meaning we can disable the rule so it doesn’t throw the error. This approach is not recommended in all cases, but it can be a quick fix if you are certain that the missing dependency is not a problem.
🌐
Bitstack
blog.bitsrc.io › understanding-dependencies-in-useeffect-7afd4df37c96
Understanding Dependencies in useEffect | Bits and Pieces
March 4, 2025 - It must — or as we’ll see later, ... of these values changes (and after the initial render). The array of dependencies is not passed as argument to the effect function....
🌐
Coder
coder.earth › post › react-hooks-oops-part-3-an-effect-does-not-run-again-when-its-dependencies-change
React hooks... Oops! Part 3 - an effect doesn't run again when its dependencies change | Łukasz Makuch
function App() { // This fragment ... to it! 😲 · Why did it work before, but doesn't work now? It's because putting values in the dependency list doesn't turn them into any sort of observables. React won't be notified when they get mutated....
Find elsewhere
Top answer
1 of 2
5

Your both dispatch are called after first render so even before your second render value is 0 so your second useEffect won't be able detect change as there is no change.

Let's see what is happening in your render method

First Render:

a = 0

first useEffect: dispatch({ a : 1 })

second useEffect: dispatch({ a : 0 })

so now in your redux store a is 0.

Second Render

a = 0

first useEffect: doesn't run as there is no dependency

second useEffect: doesn't run as a hasn't changed.

2 of 2
1

PLEASE, stop using

 useSelector(state => state.mainReducer);

it doesn't make any sense

there should be a simple state transformation (subselection)

const a = useSelector(state => state.a)

taken directly from redux docs:

const counter = useSelector(state => state.counter)  

update

you can see effect (from store change) with slightly changed component

function MyComponent(props) {
  const a = useSelector(state => state.a);
  const dispatch = useDispatch(); 

  console.log('render: ', a);

  useEffect(() => {
    console.log('use effect: ', a);
    dispatch({ type: 'A', payload: a });
  }, [a]) 

  useEffect(() => {
    console.log('did mount: ', a);
    dispatch({ type: 'A', payload: 1 })
  }, []); 

  return (<View style={styles.container}>
    <Text style={styles.text}>{a}</Text>
  </View>);
};

It should result in log:

  • render: 0 // initial state
  • use effect: 0 // first effect run
  • // dispatch 0 ... processed in store by reducer but results in the same state ...
    // ... and in our rendering process we still working on an 'old' a readed from state on the beginning of render
  • did mount: 0 // 'old' a
    // dispatch 1 ... changed state in redux store
  • .... rendered text 0
    ...
    ...

  • // useSelector forces rerendering - change detected

  • render: 1 // latest dispatched value, processed by reducers into new state, rereaded by selector
  • use effect: 1 // useEffect works AS EXPECTED as an effect of a change
  • .... rendered text 1

...
...

  • no more rerenderings - latest dispach not changed state

Of course dispatch from other component will force update in this component ... if value will be different.

Top answer
1 of 16
776

If you aren't using fetchBusinesses method anywhere apart from the effect, you could simply move it into the effect and avoid the warning

useEffect(() => {
    const fetchBusinesses = () => {
       return fetch("theURL", {method: "GET"}
    )
      .then(res => normalizeResponseErrors(res))
      .then(res => {
        return res.json();
      })
      .then(rcvdBusinesses => {
        // some stuff
      })
      .catch(err => {
        // some error handling
      });
  };
  fetchBusinesses();
}, []);

If however you are using fetchBusinesses outside of the effect, you must note two things

  1. Is there any issue with you not passing fetchBusinesses as a method when it's used during mount with its enclosing closure?
  2. Does your method depend on some variables which it receives from its enclosing closure? This is not the case for you.
  3. On every render, fetchBusinesses will be re-created and hence passing it to useEffect will cause issues. So first you must memoize fetchBusinesses if you were to pass it to the dependency array.

To sum it up I would say that if you are using fetchBusinesses outside of useEffect you can disable the rule using // eslint-disable-next-line react-hooks/exhaustive-deps otherwise you can move the method inside of useEffect

To disable the rule you would write it like

useEffect(() => {
   // other code
   ...
 
   // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) 
2 of 16
448

There are very good options for state management librariess if you are creating a new app or have enough flexibility. Check out Recoil.

Just for completeness:

1. (Stopped working) Use function as useEffect callback

useEffect(fetchBusinesses, [])

2. Declare function inside useEffect()

useEffect(() => {
  function fetchBusinesses() {
    ...
  }
  fetchBusinesses()
}, [])

3. Memoize with useCallback()

In this case, if you have dependencies in your function, you will have to include them in the useCallback dependencies array and this will trigger the useEffect again if the function's params change. Besides, it is a lot of boilerplate... So just pass the function directly to useEffect as in 1. useEffect(fetchBusinesses, []).

const fetchBusinesses = useCallback(() => {
  ...
}, [])
useEffect(() => {
  fetchBusinesses()
}, [fetchBusinesses])

4. Function's default argument

As suggested by Behnam Azimi

It's not best practice, but it could be useful in some cases.

useEffect((fetchBusinesses = fetchBusinesses) => {
   fetchBusinesses();
}, []);

5. Create a custom hook

Create a custom hook and call it when you need to run function only once. It may be cleaner. You can also return a callback to reset re-run the "initialization" when need.

// customHooks.js
const useInit = (callback, ...args) => {
  const [mounted, setMounted] = useState(false)
  
  const resetInit = () => setMounted(false)

  useEffect(() => {
     if(!mounted) {
        setMounted(true);
        callback(...args);
     }
  },[mounted, callback]);

  return [resetInit]
}

// Component.js
return ({ fetchBusiness, arg1, arg2, requiresRefetch }) => {
  const [resetInit] = useInit(fetchBusiness, arg1, arg2)

  useEffect(() => {
    resetInit()
  }, [requiresRefetch, resetInit]);

6. Disable eslint's warning

Disabling warnings should be your last resort, but when you do, better do it inline and explicitly, because future developers may be confused or create unexpected bugs without knowing linting is off

useEffect(() => {
  fetchBusinesses()
}, []) // eslint-disable-line react-hooks/exhaustive-deps
🌐
Tim Mousk
timmousk.com › blog › react-hook-useeffect-has-a-missing-dependency
How To Fix “react hook useeffect has a missing dependency”? – Tim Mouskhelichvili
March 11, 2023 - Another solution is to move the dependency inside the useEffect hook. The downside of this solution is you cannot move a hook into a hook. So it is not possible to have a useState inside a useEffect hook. With non-hooks, however, this solution works great.
🌐
DEV Community
dev.to › aasthapandey › useeffect-in-react-3flb
useEffect with and without dependency array in react - DEV Community
May 26, 2021 - Hey! thebarefootdev, even I know that the code won't do anything I was not trying to tell about Api calls or fetch or axios or async await or promise or then, I was only trying to point about the dependency array. ... I think instead of saying "In the above snippet, there is no dependency array so this will be called every time if state or props changes." we can say the useEffect function is called at the beginning of the load page instead of calling it every time.
🌐
GitHub
github.com › facebook › react › issues › 27333
Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error · Issue #27333 · facebook/react
September 4, 2023 - type AscensionModalProps = { open: boolean; onClose: () => void; member: GangMember; onAscend: () => void; }; export function AscensionModal(props: AscensionModalProps): React.ReactElement { const gang = useGang(); useRerender(1000); //Cleanup if modal is closed for other reasons, ie. ns.gang.ascendMember() useEffect(() => { return () => { props.onClose(); }; }, []); // eslint-disable-line react-hooks/exhaustive-deps // dependency array must be given and empty or modal will not open // React error wants 'props' in dependency or don't use 'props'.
Author   myCatsName
🌐
TypeOfNaN
typeofnan.dev › fix-function-makes-the-dependencies-of-useeffect-hook-change-on-every-render-warning-in-react
Fix the "Function makes the dependencies of useEffect Hook change on every render" warning in React | TypeOfNaN
However, since logCount depends on the count variable, we’ll have to add the count variable to the dependency array. ... function App() { const [count, setCount] = useState(1); useEffect(() => { const logCount = () => { console.log(count); }; logCount(); }, [count]); return <div className="App">foo</div>; } And the warning is gone! You may not want, or be able, to put logCount inside the useEffect hook.
🌐
Bobby Hadz
bobbyhadz.com › blog › react-hook-useeffect-has-missing-dependency
React Hook useEffect has a missing dependency error [Fixed] | bobbyhadz
We moved the variable declaration for the object inside of the useEffect hook. This removes the warning because the hook no longer has a dependency on the object because it is declared inside of it.
🌐
React
react.dev › learn › removing-effect-dependencies
Removing Effect Dependencies – React
(In this example, even disabling the linter would not work—if you do that, isMuted would get “stuck” with its old value.) To solve this problem, you need to extract the logic that shouldn’t be reactive out of the Effect. You don’t want this Effect to “react” to the changes in isMuted. Move this non-reactive piece of logic into an Effect Event: import { useState, useEffect, useEffectEvent } from 'react';
🌐
Reddit
reddit.com › r/reactjs › what is the purpose of useeffect without a dependency array?
r/reactjs on Reddit: What is the purpose of useEffect without a dependency array?
March 3, 2022 -

I use useEffect all the time in my applications, but I've never understood the difference between having code inside a useEffect with no dependency array, and just running it in the component itself.

From the documentation. What is the difference between this

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  });
}

and this?

function Example() {
  const [count, setCount] = useState(0);
  document.title = `You clicked ${count} times`;
}

wont both run on every render?

Edit: thanks for all the helpful responses. It seems like my intuition was almost right. It does behave slightly differently, but almost never in a way you want. However it would be good for protecting DOM manipulating functions for SSR.

🌐
Bam
bam.tech › article › how-to-avoid-bugs-in-useeffect
How to manage the useEffect dependency array like a pro?
March 1, 2022 - Discover how AI makes it possible to break free from legacy systems and unlock IT innovation · Discover how market leaders innovate, accelerate, and reinvent themselves alongside Theodo
🌐
Reddit
reddit.com › r/reactjs › react hook useeffect has a missing dependency // can't understand this warning 100%
r/reactjs on Reddit: React Hook useEffect has a missing dependency // can't understand this warning 100%
August 21, 2022 -

Hi! I was coding and opened my terminal to find I had a warning:

React Hook useEffect has a missing dependency: 'getEmergencyTasks'. Either include it or remove the dependency array.

Here's the code:

  const [currentEmergencyId, setCurrentEmergencyId] = useState(0);
  const [tasks, setTasks] = useState([]);
 
 const getEmergencyTasks = async () => {
    try {
      const response = await axios.get(`emergency/${currentEmergencyId}/tasks`);
      console.log(response.data);
      setTasks(response.data);
    } catch (error) {
      console.log(error);
    }
  };  
  useEffect(() => {
    getEmergencyTasks();
  }, [currentEmergencyId])

I don't know why I should include getEmergencyTasks function to dependency array of useEffect. The UI is working ok fetching the data when using the setCurrentEmergencyId function to mutate the currentEmergencyId variable. COuld anyone help me? Thank you!