//Example #1 - I KNOW THIS IS WRONG
this.state.myCount = this.state.myCount + 42;
//Example #2 - Why is this wrong ?
this.setState({
myCount: this.state.myCount + 42,
})
//Example #3 - proper way, as per React docs
this.setState( (prevState, props) => ({
myCount: prevState.myCount + 42
}));
Now I've been using Example#2 without ever encountering an error in 3+ years of doing React.
Why is Example#2 wrong, can someone give a counter example, that will actually display an error in the console?