Created
January 31, 2018 00:32
-
-
Save JoaoCnh/18000be61b7cb1849b9251f975498320 to your computer and use it in GitHub Desktop.
Avatar shouldComponentUpdate
This file contains 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
import React from "react"; | |
export default class Avatar extends React.Component { | |
state = { | |
open: false, | |
}; | |
shouldComponentUpdate(nextProps, nextState) { | |
const photoChanged = this.props.avatarUrl !== nextProps.avatarUrl; | |
const optionsWereToggled = this.state.open !== nextState.open; | |
return photoChanged || optionsWereToggled; | |
} | |
render() { | |
return ( | |
<div> | |
<img src={this.props.avatarUrl} /> | |
{this.state.open && (<Dropdown />)} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment