Skip to content

Instantly share code, notes, and snippets.

@mgiulio
Created September 3, 2015 16:50
Show Gist options
  • Save mgiulio/2d5e1f29e03a72873e07 to your computer and use it in GitHub Desktop.
Save mgiulio/2d5e1f29e03a72873e07 to your computer and use it in GitHub Desktop.
A mixin to log the lifecycle method invocations of a React component
var lifeCycleLogger = [
'componentWillMount',
'componentDidMount',
'componentWillUnmount',
'componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'componentDidUpdate'
].reduce(
(o, m) => {
o[m] = function() {
console.log(`${this.constructor.displayName}::${m}: `, arguments);
return true; // for componentShouldUpdate()
};
return o;
},
{}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment