Created
January 21, 2020 12:25
-
-
Save sygn/7b16eda110f07d064051279b4bca1516 to your computer and use it in GitHub Desktop.
Debug re-render cause in React
This file contains 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) { | |
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