React setState not update state
2022-08-30 02:12:31
所以我有这个:
let total = newDealersDeckTotal.reduce(function(a, b) {
return a + b;
},
0);
console.log(total, 'tittal'); //outputs correct total
setTimeout(() => {
this.setState({ dealersOverallTotal: total });
}, 10);
console.log(this.state.dealersOverallTotal, 'dealersOverallTotal1'); //outputs incorrect total
newDealersDeckTotal
只是一个数字数组,例如,但是没有给出正确的总数,但确实如此?我甚至设置了一个超时延迟,看看这是否解决了问题。任何明显的或我应该发布更多的代码?[1, 5, 9]
this.state.dealersOverallTotal
total