Skip to content

Instantly share code, notes, and snippets.

@clamstew
Created May 14, 2019 23:08
Show Gist options
  • Save clamstew/6ab99394335fec61b97a0ffc842fe146 to your computer and use it in GitHub Desktop.
Save clamstew/6ab99394335fec61b97a0ffc842fe146 to your computer and use it in GitHub Desktop.
detect prop changes in react apps for debugging
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