Created
June 14, 2018 07:52
-
-
Save SASUKE40/b96e8a2a98d03d0b84abd5b2a46ea71e to your computer and use it in GitHub Desktop.
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 EmailInput extends Component { | |
| state = { | |
| email: this.props.defaultEmail, | |
| prevPropsUserID: this.props.userID | |
| }; | |
| static getDerivedStateFromProps(props, state) { | |
| // Any time the current user changes, | |
| // Reset any parts of state that are tied to that user. | |
| // In this simple example, that's just the email. | |
| if (props.userID !== state.prevPropsUserID) { | |
| return { | |
| prevPropsUserID: props.userID, | |
| email: props.defaultEmail | |
| }; | |
| } | |
| return null; | |
| } | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment