That's not my actual code, just an mock to explain my issue.
I know the using setState function triggers a new render, but in a piece of code I'm trying to debug that seems to happens instantly, eg:
const [stateA,setStateA] = useState(false);
const [stateB,setStateB] = useState(false);
useEffetc(() => {console.log(stateA, stateB)}, [stateA,stateB]);
//async code, request callback
() =>{
setStateA(true);
setStateB(true);
}
// true false
// true true
What I got is that right after setStateA(true);
has done, a new render is triggered, that activates the console log with the partial results. After that, the js interpreter resume the execution from setStateB(true);
, with a new render.
This of course breaks the component logic, and my React knowledge, as I have always thought the the interpreter never leave a code block in the middle to do something else.