Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shuding/7b29d3dd94b96f5ce2844e4401ce462c to your computer and use it in GitHub Desktop.
Save shuding/7b29d3dd94b96f5ce2844e4401ce462c to your computer and use it in GitHub Desktop.
var pureRender = (Component) => {
Object.assign(Component.prototype, {
shouldComponentUpdate (nextProps, nextState) {
return !shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState);
}
});
};
module.exports = pureRender;
///////////////////////////////////////////////////
var pureRender = require('./pureRender');
class Foo extends React.Component {
render () {
return <div>this ain’t so bad</div>
}
}
pureRender(Foo); // don't return so you know its mutative :(
module.exports = Foo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment