what is the preferred way to mutate a React state?

concat returns a new array, so you can do

this.setState({list: this.state.list.concat([newObject])});

another alternative is React’s immutability helper

  var newState = React.addons.update(this.state, {
      list : {
        $push : [newObject]
      }
  });

  this.setState(newState);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)