简介:ShouldCompleteUpdate,下文简称SCU,就是指明什么时候component(组件)需要进行更新。
1.常见的SCU的用法:
(1)比如在下面的例子中,组件中只有2个值,props.color和state.count可以发生改变,我们可以这样
使用SCU。
class CounterButton extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 1};
}
shouldComponentUpdate(nextProps, nextState) {
if (this.props.color !== nextProps.color) {
return true;
}
if (this.state.count !== nextState.count) {
return<