Last active
August 29, 2015 14:23
-
-
Save gilbox/4bb0248ac9108cddef5a to your computer and use it in GitHub Desktop.
Classy React: elegant decorator
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
import {shouldComponentUpdate} from '../component-render-mixin'; | |
import {componentWillMount, componentWillReceiveProps} from '../statics-mixin'; | |
function elegant(DecoratedComponent) { | |
return class ElegantDecorator extends React.Component { | |
static displayName = `Elegant(${getDisplayName(DecoratedComponent)})`; | |
static DecoratedComponent = DecoratedComponent; | |
shouldComponentUpdate(nextProps, nextState) { | |
return shouldComponentUpdate.call(this, nextProps, nextState); | |
} | |
componentWillMount() { | |
return componentWillMount.call(this); | |
} | |
componentWillReceiveProps(newProps) { | |
return componentWillReceiveProps.call(this, newProps); | |
} | |
render() { | |
return (<DecoratedComponent {...this.props} />); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment