Magnificent content
The callback caught me by surprise I was expecting something like the nextTick function from Vue
While delayed is an accurate descriptor of what is happening, it should be noted that the reason setCounter seems to be delayed is because useState is an asynchronous operation.
Never came across use case where i have to call setState twice in a raw...but its good to understand the under the hood react...always use call back to update react state
I thought people knew π
this is why i like vue over react
Also one more interesting thing in React is that it would work the same way if the first setCounter stayed the same and only the second one used the callback for getting previous valueπ
Or even better just don't use react
Isn't this just directly a consequence of how lambda capture works? The variable `counter` isn't ever actually mutated, so why would it change? I don't see how this has anything to do with state updates being ""delayed,"" merely a feature of the langauge...
@hikari1690