The setState()
operation is asynchronous and hence your console.log()
will be executed before the setState()
mutates the values and hence you see the result.
To solve it, log the value in the callback function of setState()
, like:
setTimeout(() => {
this.setState({dealersOverallTotal: total},
function(){
console.log(this.state.dealersOverallTotal, 'dealersOverallTotal1');
});
}, 10)