Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Created March 12, 2019 18:58
Show Gist options
  • Save doug2k1/4d0a7886069d6028f0dc4d112f779fb7 to your computer and use it in GitHub Desktop.
Save doug2k1/4d0a7886069d6028f0dc4d112f779fb7 to your computer and use it in GitHub Desktop.
React detect changed props
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