10- Removing the Local State

[…,this.state.counters] copy the state, you can do whatever you want to do without any side-effects. This is the concept of Functional Programming.

You will be confused about the setState will eventually change the state, so why bothered.
Actually is not.The React is kind of state machine. setState will package states in to queue waiting to deal with. They are isolated with each other.

If you Change the state directly.There are many other places use the state will be changed. And also the state waiting in queue will be effected as well. Especially when you build a very large project, this behavios is very danderous. It will cause choas.

2 Likes