Skip to content

Instantly share code, notes, and snippets.

@gilbox
Last active August 29, 2015 14:23
Show Gist options
  • Save gilbox/4bb0248ac9108cddef5a to your computer and use it in GitHub Desktop.
Save gilbox/4bb0248ac9108cddef5a to your computer and use it in GitHub Desktop.
Classy React: elegant decorator
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