📌  相关文章
📜  公共问题 标签 用户 集体 探索集体 找工作 工作 公司 TEAMS Stack Overflow for Teams – 与私人团体协作和分享知识. setState 不会立即更新状态 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:39.607000             🧑  作者: Mango

代码示例1
//our state needs some time to mutate, and since console.log(this.state.boardAddModalShow) 
executes before the state mutates, you get the previous value as output. So you need 
to write the console in the callback to the setState function

this.setState({ name: "myname" }, () => {                              
        //callback
        console.log(this.state.name) // myname
      });