Skip to content

Instantly share code, notes, and snippets.

@sygn
Created January 21, 2020 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sygn/7b16eda110f07d064051279b4bca1516 to your computer and use it in GitHub Desktop.
Save sygn/7b16eda110f07d064051279b4bca1516 to your computer and use it in GitHub Desktop.
Debug re-render cause in React
componentDidUpdate(prevProps, prevState) {
Object.entries(this.props).forEach(([key, val]) =>
prevProps[key] !== val && console.log(`Prop '${key}' changed`)
);
if (this.state) {
Object.entries(this.state).forEach(([key, val]) =>
prevState[key] !== val && console.log(`State '${key}' changed`)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment