How State Actually Works: useState from the Inside
Series: How React Works Under the Hood
Part 1: Motivation Behind React Fiber: Time Slicing & Suspense
Part 2: Why React Had to Build Its Own Execution Engine
Part 3: How React Finds What Actually Changed
Part 4: The Idea That Makes Suspense Possible
Part 5: The React Lifecycle From the Inside
Prerequisites: Read Parts 1–5 first.
Three Things That Confuse Almost Everyone
Here are three behaviors of useState that trip up developers at every level:
function Counter () { const [ count , setCount ] = useState ( 0 );
function handleClick () { setCount ( count + 1 ); setCount ( count + 1 ); setCount ( count + 1 ); // You might expect count to become 3 // It becomes 1 }
function handleLog () { setCount ( count + 1 ); console .…