DEV Community

Discussion on: Build a Timer with React Hooks

 
atellmer profile image
AlexPlex

I checked useState behavoiur and I have 1 render. See example codesandbox.io/s/sweet-star-er91q?...

Thread Thread
 
viclafouch profile image
Victor de la Fouchardière • Edited

It's because it comes from an event, like a click on a button.

React currently will batch state updates if they're triggered from within a React-based event, like a button click or input change. It will not batch updates if they're triggered outside of a React event handler, like an async call.

Thread Thread
 
atellmer profile image
AlexPlex

Yea, you're right. I didn't know it. Thanks. But what's reason for work batching only in event handlers?