I made my componentWillMount()
async. Now I can using await
with the setState
.
Here is the sample code:
componentWillMount = async() => {
const { fetchRooms } = this.props
await this.setState({ })
fetchRooms()
}
So question here is this.setState
returns promise because I can use await
with it?
Edit
When I put await then it runs in a sequence 1, 2, 3
And when I remove await then it runs 1, 3, 2
??
componentWillMount = async() => {
const { fetchRooms } = this.props
console.log(1)
await this.setState({ } => {
console.log(2)
})
console.log(3)
fetchRooms()
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…