DEV Community

Discussion on: Better ReactJS patterns: this.setState pitfalls

Collapse
 
todorpr profile image
Todor Prikumov

Actually you can do:

incrementCounter = () => {
  this.setState((presentState) => (
    { ...presentState, counter: ++presentState.counter }
  ))
}
Collapse
 
promisetochi profile image
Promise Tochi

You are right, thanks for catching that