I'm trying to understand the React (functional) component lifecycle little better and I'm getting confused by useEffect() when it is given a dependency array as second argument. I've read the docs and I feel like I understand the basics of useEffect and its second argument but still would like to know a little more.
For example
A component has two state variables:
stateVarAandstateVarB.
setStateVarA()is called, component returns...render runs...reconciliation happens... there was some kind of a change so DOM is updated.
Now, this is where i get confused. If we had two useEffect(), one with [stateVarA] dependency array and another one with [stateVarB] dependency array, how does React 'know' which state variable was responsible for the latest update (since, in this case, only the useEffect(f(),[stateVarA]) will run)? is this information stored somewhere in the state object? I feel like I'm missing something basic here.
useeffectwith a data as second argument will call the functions inside of it whenever given data has changed since the previous one, now if you use twouseEffects each one will call the defined functions according to data, try to log something in useeffects and change the data in the app to get better idea