my function looks like this:
this.setState(prevState => ({
time : prevState.time + 1
}), function() {
doSomethingWithNewState(this.state.time)
})
is it correct to use await in this situation? like this:
await this.setState(prevState => ({
time : prevState.time + 1
}));
doSomethingWithNewState(this.state.time);
No this.setState
doesn't return a promise.
So you can't use await in this case. You need to use the callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With