DEV Community

Discussion on: We don't know how React state hook works

Collapse
adamklein profile image
adam klein Author

Hi,
glad you learned something :)

That's the eager computation.

I think React tries to optimize based on the prediciton that the previous outcome will repeat itself.
So if the last time the state changed, it will start with lazy computation. But if the last time the state didn't change - it will start from eager computation. But that's just my guess, I haven't seen that in the code and I honestly have no idea.

I tried to demonstrate it here (forked your stackblitz):
stackblitz.com/edit/react-sync-asy...

Collapse
kosich profile image
Kostia Palchyk • Edited

Right you are! Thanks and sorry, missed that one while reading first time.