Skip to content

Instantly share code, notes, and snippets.

@Prinzhorn Prinzhorn/index.js
Created Sep 18, 2015

Embed
What would you like to do?
Quick and dirty way to debug which prop/state changes caused react update
componentDidUpdate: function(prevProps, prevState) {
var differentProps = {};
var differentState = {};
var k;
for(k in prevProps) {
if(prevProps[k] !== this.props[k]) {
differentProps[k] = [prevProps[k], this.props[k]];
}
}
for(k in this.props) {
if(prevProps[k] !== this.props[k]) {
differentProps[k] = [prevProps[k], this.props[k]];
}
}
for(k in prevState) {
if(prevState[k] !== this.state[k]) {
differentState[k] = [prevState[k], this.state[k]];
}
}
for(k in this.state) {
if(prevState[k] !== this.state[k]) {
differentState[k] = [prevState[k], this.state[k]];
}
}
console.log(differentProps, differentState);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.