Skip to content

Instantly share code, notes, and snippets.

@aduth
Last active April 26, 2018 17:51
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 aduth/1de66c6bc7cc372cb93c5ca611f9d6b9 to your computer and use it in GitHub Desktop.
Save aduth/1de66c6bc7cc372cb93c5ca611f9d6b9 to your computer and use it in GitHub Desktop.
componentDidUpdate Changed Props
class MyComponent extends React.Component {
// ...
componentDidUpdate( prevProps ) {
for ( const key of Object.keys( this.props ) ) {
if ( this.props[ key ] !== prevProps[ key ] ) {
console.log(
key,
`(Before: ${ prevProps[ key ] })`,
`(After: ${ this.props[ key ] })`
);
}
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment