Given the following simple component:
const MyComponent = () => {
const [state, setState] = useState("");
useEffect(function a() {
// Do stuff
setState("Some value");
}, [])
useEffect(function b() {
// Do stuff
}, [state]);
// return some fancy JSX
}
The execution order will be:
MyComponentmounts andMyComponent()executes and returns JSX.- function
ais executed and the state change gets queued. - function
bis executed (The state change from 2) is not yet reflected, sostate === "").
Now my question is, given that state might change by other triggers than drafted here, is there any guarantee that the setState("Some value") from function a will have happened by the time the effect b is executed the next time (after step 3) above)?
In other words, may there be any constellation where b will be called because state has changed, but the setState("Some value") from a has not happened yet?