DEV Community

Discussion on: 3 Mistakes to avoid when updating React state

Collapse
 
geordyjames profile image
Geordy James

The second parameter of setState is a callback. So this will work too...

    this.setState(
      {
        count: this.state.count + 1
      },
      () => {
        console.log(this.state);
      }
    );
Collapse
 
anantbahuguna profile image
Anant Bahuguna

Yup this works too. Thnx for reminding.