Last active
July 27, 2018 09:22
-
-
Save lukewang1024/e4a598ba80e076d9b2ce5edd6f3f7834 to your computer and use it in GitHub Desktop.
[React useful snippets] Some useful React snippets #react
This file contains hidden or 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
| class Demo extends React.Component { | |
| componentDidUpdate(prevProps, prevState) { | |
| for (const i in this.props) { | |
| if (this.props[i] !== prevProps[i]) { | |
| console.log(`prop ${i} changed from ${prevProps[i]} to ${this.props[i]}`); | |
| } | |
| } | |
| for (const i in this.state) { | |
| if (this.state[i] !== prevState[i]) { | |
| console.log(`state ${i} changed from ${prevState[i]} to ${this.state[i]}`); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment