setState doesn't update the state immediately

前端 未结 12 2538
暖寄归人
暖寄归人 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条回答
  •  旧时难觅i
    2020-11-21 05:47

    If you want to track the state is updating or not then the another way of doing the same thing is

    _stateUpdated(){
      console.log(this.state. boardAddModalShow);
    }
    
    openAddBoardModal(){
      this.setState(
        {boardAddModalShow: true}, 
        this._stateUpdated.bind(this)
      );
    }
    

    This way you can call the method "_stateUpdated" every time you try to update the state for debugging.

提交回复
热议问题