Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active October 6, 2016 21:44
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ryanflorence/a93fd88d93cbf42d4d24 to your computer and use it in GitHub Desktop.
Save ryanflorence/a93fd88d93cbf42d4d24 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;
@dlong500
Copy link

@brigand
Can you elaborate on your statement "In any cases that are more complex than a single lifecycle hook, this doesn't work as well".

What exactly are the drawbacks to this same approach that is also now listed in the official React docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment