Skip to content

Instantly share code, notes, and snippets.

@acdlite
Last active July 17, 2019 09:29
Show Gist options
  • 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;
@acdlite
Copy link
Author

acdlite commented Mar 30, 2015

Good idea? Terrible idea? Is an HoC overkill in this case, since it's just one method? ¯_(ツ)_/¯

@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