Skip to content

Instantly share code, notes, and snippets.

@wklsh
Last active November 13, 2018 10:58
Show Gist options
  • Save wklsh/869020a94814d51e403394a7929b6d9c to your computer and use it in GitHub Desktop.
Save wklsh/869020a94814d51e403394a7929b6d9c to your computer and use it in GitHub Desktop.
Check for updated props / states within ComponentDidUpdate lifecycle
componentDidUpdate(prevProps, prevState) {
// Get updated props
for (const index in prevProps) {
if (prevProps[index] !== this.props[index]) {
console.log(index, prevProps[index], "-->", this.props[index]);
}
}
// Get updated states
for (const index in prevState) {
if (prevState[index] !== this.state[index]) {
console.log(index, prevState[index], "-->", this.state[index]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment