小编Nic*_*ick的帖子

reactjs:ShouldComponentUpdate for states

我怎样才能shouldComponentUpdate用于州?

我可以查一下:

shouldComponentUpdate(nextProps, nextState) {
  return this.state.value != nextState.value;
}
Run Code Online (Sandbox Code Playgroud)

但它对国家没有任何意义.因为如果我改变state(this.setState({value: 'newValue'}))this.state将是平等的 nextState.

例如,onClick事件:

handleClick() {
  this.setState({value: 'newValue'});
}
Run Code Online (Sandbox Code Playgroud)

reactjs

29
推荐指数
1
解决办法
4万
查看次数

标签 统计

reactjs ×1