为什么使用新值的setState比修改后的状态值更有效?

时间:2018-10-18 12:35:17

标签: reactjs

为什么如本article中所述,代码段1比代码段2更有效?

//snippet 1
handleClick() {
  this.setState(state => ({
    words: state.words.concat(['marklar'])
  }));
}

//snippet 2
handleClick() {
    const words = this.state.words;
    words.push('marklar');
    this.setState({words: words});
}

0 个答案:

没有答案