https://facebook.github.io/react/docs/shallow-compare.html
shallowCompare jest funkcja pomocnika, aby osiągnąć tę samą funkcjonalność jako PureRenderMixin podczas korzystania z klas ES6 React.
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>;
}
}
Source code od PureRenderMixin
jest:
var ReactComponentWithPureRenderMixin = {
shouldComponentUpdate: function(nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
},
};
Więc, kiedy użyć PureRenderMixin
, faktycznie korzysta shallowCompare
UPDATE 15.3.0:
Dodaj React.PureComponent
- nowa klasa podstawowa do rozszerzenia, zastępująca react-addons-pure-render-mixin
teraz, gdy mixiny nie działają z klasami ES2015.
doceniam to robisz badania dla mnie :) –