first of all, here is my first piece of code:
let testValue = this.state.testValue;
this.setState({testValue: testValue + 1});
console.log(this.state.testValue);
this.setState({testValue: testValue + 1});
console.log(this.state.testValue);
setTimeout(() => {
// testValue
this.setState({testValue:testValue + 1});
console.log(this.state.testValue);
this.setState({testValue:testValue + 1});
console.log(this.state.testValue);
}, 0);
The output in console on the page is:
:
let testValue = this.state.testValue;
Why? at the beginning of ps:, the default value of testValue is 1. Please do not hesitate to comment.