Correct way to update State using the existing state:



this.setState((state, props) => ({

                property: state.counter + props.increment

}));

 

or using regular functions:

 

this.setState(function(state, props) {

  return {

    counter: state.counter + props.increment

  };

});

Comments

Popular posts from this blog

Set Up Babel and Webpack

Typescript Setup

Typescript + React Setup