Created
March 14, 2019 09:22
-
-
Save paoloiulita/6b01f8734acda35f53892addd47bc5a2 to your computer and use it in GitHub Desktop.
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, prevState) { | |
Object.keys(prevProps) | |
.filter(key => (prevProps[key] !== this.props[key])) | |
.map(key => { | |
if (typeof prevProps[key] === 'object' || typeof this.props[key] === 'object') { | |
console.log(`changed prop: ${key}`); | |
console.log(prevProps[key]); | |
console.log(this.props[key]); | |
} else { | |
console.log(`changed prop: ${key} from ${prevProps[key]} to ${this.props[key]}`); | |
} | |
}); | |
Object.keys(prevState) | |
.filter(key => (prevState[key] !== this.state[key])) | |
.map(key => { | |
if (typeof prevState[key] === 'object' || typeof this.state[key] === 'object') { | |
console.log(`changed state: ${key}`); | |
console.log(prevState[key]); | |
console.log(this.state[key]); | |
} else { | |
console.log(`changed state: ${key} from ${prevState[key]} to ${this.state[key]}`); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment