Skip to content

Instantly share code, notes, and snippets.

@acdlite
Last active July 17, 2019 09:29
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save acdlite/453f227f5e5cbbf105f8 to your computer and use it in GitHub Desktop.
Save acdlite/453f227f5e5cbbf105f8 to your computer and use it in GitHub Desktop.
Pure Render Mixin in ES6
function pureRenderMixin(Component) {
Component.prototype.shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState);
}
return Component;
}
class MyComponent extends React.Component {}
pureRenderMixin(MyComponent);
export default MyComponent;
@burabure
Copy link

Decorators will probably be a better fit, but i think this will probably be better that something like this https://gist.github.com/ryanflorence/a93fd88d93cbf42d4d24 for now

@angus-c
Copy link

angus-c commented May 7, 2015

I wrote a universal react mixin util that accepts traditional react mixins and ES6 class mixins
https://github.com/angus-c/es6-react-mixins

import mixin from 'es6-react-mixins'
class MyComponent extends mixin(ReactAddOns.addons.PureRenderMixin) {}

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