-
-
Save mmolucio/b38203cd51fe672a2376b92e2f578985 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