Created
December 5, 2018 06:59
-
-
Save stevenhao/b3243961f6379f5811954b2a1aa7d4be to your computer and use it in GitHub Desktop.
snippet to debug unexpected pure component updates
This file contains hidden or 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, prevState) { | |
const diff = (o1, o2) => ( | |
_.map(_.filter(_.uniq([..._.keys(o1), ..._.keys(o2)]), key => o1[key] !== o2[key]), key => ({ | |
key, | |
v1: o1[key], | |
v2: o2[key], | |
})) | |
); | |
console.log('DIFF', { props: diff(prevProps, this.props), state: diff(prevState, this.state) }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment