Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
The setter schedules an update for the next render; the count variable in the current render is a constant snapshot and never changes.
Each render gets its own values of state, like a snapshot. Calling the setter does not change the variable you already have; it asks React to render again with a new value. React also batches several updates made in the same event into one re-render. If you need the new value immediately, compute it into a local variable first, and if the next value depends on the previous one, use the updater form setCount(c => c + 1).