In this video, we'll dig into how useState() works, in a nutshell
1. each useState call creates a hook node in a linked list on Fiber,
2. each hook node has a update queue (linked list )holding the updates, also the current state
3. for the initial mount, useState() just sets things up and create a closure setState to trigger update
4. setState() calls creates update nodes in 2 and schedule a rerender
5. in rerender, update queue will be processed and current state is updated.
Check out my blog for this post: https://jser.dev/2023-06-19-how-does-usestate-work/
Memo: https://github.com/JSerZANP/react-source-code-walkthrough-en/blob/main/memo/react%205.png
Hi I'm a JavaScript engineer who is not good at algorithms,
and currently practicing leetCode & BFE.dev. If you are interested, maybe we can learn together.