@hikari1690

Oh my god. If only this short came out 3 years ago haha.
I knew the problem was that the value updates once per render but never knew you can use prev => prev as a callback!
As a junior dev, the most daunting thing is to read documentation. Thank you for giving resources to help us avoid it! πŸ˜‚.

@sayiganormanhaq4405

Magnificent content

@kyngcytro

The callback caught me by surprise I was expecting something like the nextTick function from Vue

@jasongates6894

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.

@pratiksavaliya3890

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

@hassantanoli9342

I thought people knew πŸ˜‚

@_ramar

this is why i like vue over react

@mCov02

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πŸ˜…

@christopherparke9878

Or even better just don't use react

@inferior2884

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