Created
March 27, 2019 16:04
-
-
Save vbfox/deb17c4f7a740baa5e6a673fb4c57c45 to your computer and use it in GitHub Desktop.
Trace props or state that changed and made a React PureComponent refresh
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
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