Created
April 12, 2017 15:55
-
-
Save albertorestifo/83877c3e4c81066a592a47c4dcf6753b to your computer and use it in GitHub Desktop.
Logs the diff between current and previous props on a react element
This file contains 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
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)}`)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here it is.. I can't do PR on gitst.
https://gist.github.com/Pablion/88428f51b12ce3836a7f20c8bb00264a