Tanvi Kulkarni2 months agoMost voted9
setCount doesn't change the `count` variable you have, it asks React to re-render with a new value. Your handleClick is still running with the `count` from the current render, so it logs the old one. The new value shows up in the next render.
If you need the new value right away just compute it:
const next = count + 1;
setCount(next);
console.log(next);