Skip to content

Instantly share code, notes, and snippets.

@lukewang1024
Last active July 27, 2018 09:22
Show Gist options
  • Select an option

  • Save lukewang1024/e4a598ba80e076d9b2ce5edd6f3f7834 to your computer and use it in GitHub Desktop.

Select an option

Save lukewang1024/e4a598ba80e076d9b2ce5edd6f3f7834 to your computer and use it in GitHub Desktop.
[React useful snippets] Some useful React snippets #react
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