Answers for "PUBLIC Questions Tags Users COLLECTIVES Explore Collectives FIND A JOB Jobs Companies TEAMS Stack Overflow for Teams – Collaborate and share knowledge with a private group. setState doesn't update the state immediately"

0

PUBLIC Questions Tags Users COLLECTIVES Explore Collectives FIND A JOB Jobs Companies TEAMS Stack Overflow for Teams – Collaborate and share knowledge with a private group. setState doesn't update the state immediately

//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
      });
Posted by: Guest on October-05-2021

Code answers related to "PUBLIC Questions Tags Users COLLECTIVES Explore Collectives FIND A JOB Jobs Companies TEAMS Stack Overflow for Teams – Collaborate and share knowledge with a private group. setState doesn't update the state immediately"

Browse Popular Code Answers by Language