Created
May 14, 2019 23:08
-
-
Save clamstew/6ab99394335fec61b97a0ffc842fe146 to your computer and use it in GitHub Desktop.
detect prop changes in react apps for debugging
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
MyComp extends PureComponent { | |
lastProps = {}; | |
whatChanged() { | |
Object.keys(this.props) | |
.filter(key => { | |
return this.props[key] !== this.lastProps[key]; | |
}) | |
.map(key => { | |
console.log("changed property:", key, "from", this.lastProps[key], "to", this.props[key]); | |
}); | |
this.lastProps = this.props; | |
} | |
render =() => { | |
this.whatChanged(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment