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
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.

🌐
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....
Discussions

Bug: useEffect closure not called when dependencies changed
I run into a very weird issue where the dependency of useEffect changes, but its closure is not called. The component renders correctly with the updated value due to a state change of a parent rout... More on github.com
🌐 github.com
17
March 8, 2022
Bug: useEffect is triggered even if the array as dependency variable wasn't changed.
[1, 2, 3] == [1, 2, 3] is false: ... not value." ... const [arrVar, setArrVar] = useState([]); useEffect(() => { console.log("triggered"); console.log(arrVar); }, [arrVar]) //Click the button twice. return ( {setArrVar([1, 2, 3])} }>update state ); useEffect is triggered even if the array element in the dependency array doesn't change when ... More on github.com
🌐 github.com
7
June 29, 2024
Useeffect not getting called immedietly as dependency value changes
I am very new to react. I am experimenting with react and trying to undertand it's concepts right now. I have a component that has two states,Name and room. I am using setstate to set room and name More on stackoverflow.com
🌐 stackoverflow.com
September 26, 2021
React.useEffect not triggering when dependency has changed
Edit: I found the solution to this! See my answer below. So essentially, I have a slice of state that is updating but not triggering the useEffect that has it as a dependency: const [editablePartic... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › facebook › react › issues › 24042
Bug: useEffect closure not called when dependencies changed · Issue #24042 · facebook/react
March 8, 2022 - I run into a very weird issue where the dependency of useEffect changes, but its closure is not called. The component renders correctly with the updated value due to a state change of a parent router, just the useEffect closure is not called.
Author   fabb
🌐
DEV Community
dev.to › cassidoo › when-useeffect-runs-3pf3
When useEffect runs - DEV Community
June 4, 2024 - Try using a ref in the dependency array and change it, the useEffect will NEVER run after that change because ref will never cause a re-render. Again, it's a small nuance, but it's important to get the difference to better understand the model.
🌐
Medium
omarshishani.medium.com › why-useeffect-is-not-updating-when-props-change-c2e603a7e98b
Why useEffect is Not Updating When props Change 👻 | by Omar Shishani | Medium
January 9, 2021 - Why won’t my component register the changed values of props??? The answer for me was that I was not passing in props to useEffect as a dependency. It didn't even occur to me that it was useEffect which was causing the problem. In many cases, I use useEffect like componentDidMount.
🌐
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 - Additionally (and consequentially), you should not expect any change in such values to result in the effect callback getting called. If you need the callback to be called when those things change, then you need to put it in useState (or useReducer).
Find elsewhere
🌐
DhiWise
dhiwise.com › post › how-to-fix-useeffect-not-triggering-in-your-react-project
Reasons Why UseEffect Is Not Triggering In Your React App
May 29, 2024 - Sometimes developers encounter ... not triggering as expected. This can be due to several reasons, such as an incorrect dependency array or the absence of dependencies that should trigger the effect.
🌐
React
react.dev › reference › react › useEffect
useEffect – React
However, you can express that you ... to changes even though it is called from inside an Effect. Declare an Effect Event with the useEffectEvent Hook, and move the code reading shoppingCart inside of it: ... Effect Events are not reactive and must always be omitted from dependencies of your Effect. This is what lets you put non-reactive code (where you can read the latest value of some props ...
🌐
GitHub
github.com › facebook › react › issues › 30141
Bug: useEffect is triggered even if the array as dependency variable wasn't changed. · Issue #30141 · facebook/react
June 29, 2024 - Link to code example: const [arrVar, ... 2, 3])} }>update state</button> ); useEffect is triggered even if the array element in the dependency array doesn't change when updated....
Author   enesgorkemgenc
🌐
Stack Overflow
stackoverflow.com › questions › 72393420 › react-useeffect-not-triggering-when-dependency-has-changed
React.useEffect not triggering when dependency has changed
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Edit: I found the solution to this! See my answer below. So essentially, I have a slice of state that is updating but not triggering the useEffect that has it as a dependency: const [editableParticipants, setEditableParticipants] = useState(*initial value*); const [joinLeftTimeState, setJoinLeftTimeState] = useState(*initial value*); function addParticipant(newParticipant) { setEditableParticipants([ ...editableParticipants, newParticipant ]) } useEffect(() => { setJoinLeftTimeState( editableParticipants.map(*mapping stuff*) ); }, [editableParticipants]);
🌐
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 - This means when any of the values ... is re-executed. In a situation where a variable that the effect depends on is not included in the dependency array, the effect may not be re-executed when the value changes....
🌐
Stack Overflow
stackoverflow.com › questions › 70052611 › useeffect-is-not-working-event-after-changing-the-dependency-state
reactjs - useEffect is not working event after changing the dependency state - Stack Overflow
It doesn't work for the second time because it depends on: -Boolean state (this is the one that makes it run the first time, by changing from false to true). -Two refs: those won't cause the effect to run because they don't change as long as the component exists (only their .current value will change and you can't put them in the dependencies array anyway.
🌐
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.
🌐
GitHub
github.com › facebook › react › issues › 15577
useEffect: separate refreshing dependencies from running effect · Issue #15577 · facebook/react
May 6, 2019 - Do you want to request a feature or report a bug? Looking for a clarification. useEffect assumes a connection between a change in dependencies and the effect running. Following the exhaustive dependencies rule, I'm running into quite a f...
Author   gnordhielm
🌐
GitHub
github.com › tannerlinsley › react-query › issues › 2628
Bug: useEffect not triggering on [deps] change · Issue #2628 · TanStack/query
September 2, 2021 - useEffect message is not visible upon clicking, even though [dependency] changed and UI is rerendered.
Author   Tosheen
🌐
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';
🌐
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....