Skip to content

Instantly share code, notes, and snippets.

@motiz88
Created September 22, 2015 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motiz88/3db323f018975efce575 to your computer and use it in GitHub Desktop.
Save motiz88/3db323f018975efce575 to your computer and use it in GitHub Desktop.
React lifecycle method grouping, using a decorator
import methodGroups fom './method-groups-decorator';
@methodGroups('lifecycle')
class Example extends React.Component {
static lifecycle = {
componentWillMount() {},
componentDidMount() {},
componentWillReceiveProps() {},
shouldComponentUpdate() {},
componentWillUpdate() {},
componentDidUpdate() {},
componentWillUnmount() {}
}
}
export default Example;
export default function methodGroups(...groups) {
return function decorator(target) {
groups.forEach(group => Object.assign(target.prototype, target[group]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment