Last active
April 26, 2018 17:51
-
-
Save aduth/1de66c6bc7cc372cb93c5ca611f9d6b9 to your computer and use it in GitHub Desktop.
componentDidUpdate Changed Props
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
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