Last active
May 16, 2017 15:30
-
-
Save arqex/2f0d69fc80cfa7e33330754e33aa6afd to your computer and use it in GitHub Desktop.
Render selectively
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
// This is our awesome component to render the current user | |
class Me extends React.Component { | |
render(){ | |
// the component receives freezer.get().me in the prop `user` | |
var me = this.props.user; | |
return ( | |
<div className="me"> | |
<h2>{ me.name }</h2> | |
</div> | |
); | |
} | |
shouldComponentUpdate( prevProps ){ | |
// `user` is immutable, so if it has changed from the previous | |
// state, it needs to be a completely different object. | |
// No need to deep checking for changes | |
return prevProps.user !== this.props.user; | |
} | |
} | |
// This won't make the component `Me` try to re-render | |
freezer.get().friends.push(66); | |
// This will re-render the component `Me` | |
freezer.get().me.hobbies.push('chess'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment