在我的反應shouldComponentUpdate函數,this.props和nextprops具有所有相同的屬性,但它們不相等。我的代碼:在我的反應shouldComponentUpdate函數,this.props和nextprops具有所有相同的屬性,但它們不相等
shouldComponentUpdate(nextProps) {
console.log(this.props);
console.log(nextProps);
console.log('nextProps vs this.props:', nextProps === this.props);
console.log('this.props.style vs nextProps.style:', this.props.style === nextProps.style);
console.log('this.props.data vs nextProps.data',this.props.data === nextProps.data);
return true;
}
我的困惑是道具是否有一些隱藏屬性。
你有沒有嘗試過反應PureComponent或react-addon-shallow-比較 – Muhaimin
[如何確定兩個JavaScript對象的相等性?](https://stackoverflow.com/questions/201183/how-to-determine -equality-for-two-javascript-objects) –
我會試一試。謝謝你,@ Muhaimin – sunt