Siarhei Fedasenka’s Post

Why does this log 1, not 2? Most people say: “Because React batches updates.” That’s only half the story. The real reason? Stale closures. Inside this render, count is 0. Both setCount(count + 1) calls use that same captured value. So React receives: 1) set to 1 2) set to 1 Not: 1) set to 1 2) set to 2 This question isn’t about memorizing hooks. It tests whether you understand how React renders create new function scopes — and how state updates are queued. #react #javascript #frontend

  • text

To view or add a comment, sign in

Explore content categories