Skip to content

Instantly share code, notes, and snippets.

@Prinzhorn
Created September 18, 2015 14:46
Show Gist options
  • Save Prinzhorn/ceb2156f8570a3745dd8 to your computer and use it in GitHub Desktop.
Save Prinzhorn/ceb2156f8570a3745dd8 to your computer and use it in GitHub Desktop.
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