New to react-js.
Recently, have gone through the blogs on the following case
Case 1:
state = {
count :1
}
L1: this.setState({count:this.state.count +1});
L2: this.setState({count:this.state.count +1});
L3: ..Multiple Times..
Value of count is 2
Case 2:
state = {
count :1
}
L4: this.setState(prevState => ({count:prevState.count+1}));
L5: this.setState(prevState => ({count:prevState.count+1}));
L6: ..Multiple Times..
Value of count is > 3
As per the doc, calling setState multiple times will be queued for the batch update(expcetions are too there).
So as per my understanding, prevState is nothing but the prevState of the current state.
This made me to think,
Q1. If the state is not holding the updated value (case 1), then how
the prevState (case 2) will hold the updated value?
Could someone clarify here?