第六章关于connect中shouldComponent的实现有误
fEyebrow opened this issue · comments
lj commented
原代码:
shouldComponentUpdate(nextProps, nextState) {
for (const propType in nextProps) {
if (nextProps.hasOwnProperty(propType)) {
if (nextProps[propType] === this.props[propType]) {
return true;
}
}
}
for (const propType in this.props) {
if (this.props.hasOwnProperty(propType)) {
if (nextProps[propType] === this.props[propType]) {
return true;
}
}
}
return false;
}
应该是:
shouldComponentUpdate(nextProps, nextState) {
for (const propType in nextProps) {
if (nextProps.hasOwnProperty(propType)) {
if (nextProps[propType] !== this.props[propType]) {
return true;
}
}
}
for (const propType in this.props) {
if (this.props.hasOwnProperty(propType)) {
if (nextProps[propType] !== this.props[propType]) {
return true;
}
}
}
return false;
}
if判断处有误