https://facebook.github.io/react/docs/shallow-compare.html
shallowCompare PureRenderMixin रूप में एक ही कार्यक्षमता प्राप्त करने के लिए एक सहायक समारोह प्रतिक्रिया के साथ ES6 कक्षाओं का उपयोग करते समय है।
import shallowCompare from 'react-addons-shallow-compare';
export default class SampleComponent extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
// pure render
return shallowCompare(this, nextProps, nextState);
}
render() {
return <div className={this.props.className}>foo</div>;
}
}
PureRenderMixin
की Source code है:
var ReactComponentWithPureRenderMixin = {
shouldComponentUpdate: function(nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
},
};
तो, जब आप PureRenderMixin
उपयोग करते हैं, आप वास्तव में उपयोग shallowCompare
अद्यतन 15.3.0:
जोड़े- विस्तार करने के लिए एक नई बेस क्लास, react-addons-pure-render-mixin
को बदलकर अब मिश्रित ES2015 कक्षाओं के साथ काम नहीं करते हैं।
स्रोत
2016-02-28 13:34:19
मैं तुम मुझे :) –