Skip to content

Instantly share code, notes, and snippets.

@fedyk
Last active November 29, 2018 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedyk/400789c5c0fe2abaf3a6a242ebd43c17 to your computer and use it in GitHub Desktop.
Save fedyk/400789c5c0fe2abaf3a6a242ebd43c17 to your computer and use it in GitHub Desktop.
what was changed
class App extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
const nextPropsKeys = Object.keys(nextProps);
const nextStateKeys = Object.keys(nextState);
for (let i = 0; i < nextPropsKeys.length; i++) {
const key = nextPropsKeys[i];
if (nextProps[key] !== this.props[key]) {
console.log(`App: props.${key} has changed`);
}
}
for (let i = 0; i < nextStateKeys.length; i++) {
const key = nextPropsKeys[i];
if (nextState[key] !== this.state[key]) {
console.log(`App: state.${key} has changed`);
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment