DEV Community

Discussion on: React Clean Code - Simple ways to write better and cleaner code

 
thawkin3 profile image
Tyler Hawkins

Not quite, again. The examples are the code snippets provided in this article, and the demo is found on the site I posted. So you can easily verify this.

The thing to note is that you will only run into trouble if the state updates are batched. So most of the time, you'll be fine writing the code without using a function, like you said. But, you will always be safe if you choose to write the code the correct way if it relies on the previous state, even if the state updates are batched. So it's safer to write it this way.