Last active
July 17, 2019 09:29
-
-
Save acdlite/453f227f5e5cbbf105f8 to your computer and use it in GitHub Desktop.
Pure Render Mixin in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
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
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
Good idea? Terrible idea? Is an HoC overkill in this case, since it's just one method? ¯_(ツ)_/¯