Does this.setState return promise in react

后端 未结 6 1192
陌清茗
陌清茗 2020-12-03 07:19

I made my componentWillMount() async. Now I can using await with the setState.

Here is the sample code:

compon         


        
6条回答
  •  庸人自扰
    2020-12-03 08:00

    setState does not return a promise.

    setState has a callback.

    this.setState({
        ...this.state,
        key: value,
    }, () => {
        //finished
    });
    

提交回复
热议问题