Created
March 12, 2019 18:58
-
-
Save doug2k1/4d0a7886069d6028f0dc4d112f779fb7 to your computer and use it in GitHub Desktop.
React detect 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
componentDidUpdate(prevProps: Props) { | |
console.log('UPDATE'); | |
Object.keys(this.props) | |
.filter(key => this.props[key] !== prevProps[key]) | |
.map(key => { | |
console.log( | |
'changed property:', | |
key, | |
'from', | |
prevProps[key], | |
'to', | |
this.props[key] | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment