Skip to content

Instantly share code, notes, and snippets.

@vbfox
Created March 27, 2019 16:04
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 vbfox/deb17c4f7a740baa5e6a673fb4c57c45 to your computer and use it in GitHub Desktop.
Save vbfox/deb17c4f7a740baa5e6a673fb4c57c45 to your computer and use it in GitHub Desktop.
Trace props or state that changed and made a React PureComponent refresh
export class Test extends React.PureComponent<{}, {}> {
UNSAFE_componentWillUpdate(nextProps: any, nextState: any) {
const changedProps = _.reduce(
this.props,
(result: string[], value, key) => value === nextProps[key] ? result : result.concat(key),
[]);
console.log("changedProps: ", changedProps);
const changedStates = _.reduce(
this.state,
(result: string[], value, key) => value === nextState[key] ? result : result.concat(key),
[]);
console.log("changedStates: ", changedStates);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment