Skip to content

Instantly share code, notes, and snippets.

@stevenhao
Created December 5, 2018 06:59
Show Gist options
  • Save stevenhao/b3243961f6379f5811954b2a1aa7d4be to your computer and use it in GitHub Desktop.
Save stevenhao/b3243961f6379f5811954b2a1aa7d4be to your computer and use it in GitHub Desktop.
snippet to debug unexpected pure component updates
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