Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@acdlite acdlite commented Mar 30, 2015

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

@burabure

This comment has been minimized.

Copy link

@burabure burabure commented Apr 26, 2015

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

This comment has been minimized.

Copy link

@angus-c 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