One of the reasons your class-based component was more complex than the functional one was that you unnecessarily used the function-argument form of setState(). You could have just used
Because of the async nature.
If you spam the button it might only increment it by one, since the state at that point at the second click isn't updated yet.
One of the reasons your class-based component was more complex than the functional one was that you unnecessarily used the function-argument form of setState(). You could have just used
onIncrement = () => this.setState(
{counter: this.state.counter + 1}
);
instead.
This could be buggy in some cases.
How so?
Because of the async nature.
If you spam the button it might only increment it by one, since the state at that point at the second click isn't updated yet.
Ah, got it, thanks!