Skip to content

Instantly share code, notes, and snippets.

@NoamELB
Last active January 28, 2019 01:31
Show Gist options
  • Save NoamELB/38ca0831e9617126d8de1a088c8207f3 to your computer and use it in GitHub Desktop.
Save NoamELB/38ca0831e9617126d8de1a088c8207f3 to your computer and use it in GitHub Desktop.
component that should not update
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