Last active
September 25, 2018 11:00
-
-
Save NoamELB/1588ea8398d989a0841ad06773e379e1 to your computer and use it in GitHub Desktop.
component that should not update and will not update when not intended
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 { | |
shouldComponentUpdate(nextProps, nextState) { | |
return this.props.type !== nextProps.type; | |
} | |
render() { | |
return 'I am rendering...'; | |
} | |
} | |
function Parent({someCondition}) { | |
let child, type; | |
if (someCondition) { | |
child = <div className="type_b" />; | |
type = 'b'; | |
} else { | |
child = <div className="type_a" />; | |
type = 'a'; | |
} | |
return ( | |
<ShouldNotUpdate type={type}> | |
{child} | |
</ShouldNotUpdate> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment