Skip to content

Instantly share code, notes, and snippets.

@albertorestifo
Created April 12, 2017 15:55
Show Gist options
  • Save albertorestifo/83877c3e4c81066a592a47c4dcf6753b to your computer and use it in GitHub Desktop.
Save albertorestifo/83877c3e4c81066a592a47c4dcf6753b to your computer and use it in GitHub Desktop.
Logs the diff between current and previous props on a react element
componentDidUpdate(prevProps) {
console.log('Rrow update diff:');
const now = Object.entries(this.props);
const added = now.filter(([key, val]) => {
if (prevProps[key] === undefined) return true;
if (prevProps[key] !== val) {
console.log(`${key}
- ${JSON.stringify(val)}
+ ${JSON.stringify(prevProps[key])}`);
}
return false;
});
added.forEach(([key, val]) => console.log(`${key}
+ ${JSON.stringify(val)}`));
}
@PabloLION
Copy link

I used only once XD. but I like it!

@PabloLION
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment