setState doesn't update the state immediately

前端 未结 12 2495
暖寄归人
暖寄归人 2020-11-21 05:25

I would like to ask why my state is not changing when I do an onclick event. I\'ve search a while ago that I need to bind the onclick function in constructor but still the s

12条回答
  •  独厮守ぢ
    2020-11-21 05:59

    This callback is really messy. Just use async await instead:

    async openAddBoardModal(){
        await this.setState({ boardAddModalShow: true });
        console.log(this.state.boardAddModalShow);
    }
    

提交回复
热议问题