Last active
January 28, 2019 01:31
-
-
Save NoamELB/38ca0831e9617126d8de1a088c8207f3 to your computer and use it in GitHub Desktop.
component that should not update
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 ShouldNotUpdate extends React.Component { | |
constructor(props) { | |
super(props); | |
this.counter = 0; | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
return this.props.children !== nextProps.children; | |
} | |
render() { | |
return `I should be rendered only 1 time. actual times rendered: ${++this.counter}`; | |
} | |
} | |
// In parent render: <ShouldNotUpdate><div/></ShouldNotUpdate> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment