ref(info): derive when to clear the entered password state

This commit is contained in:
Leonard Kim 2018-10-28 19:11:03 -07:00 committed by Leonard Kim
parent c28c70fb2f
commit e0cbb838be
1 changed files with 11 additions and 14 deletions

View File

@ -55,6 +55,17 @@ type State = {
* @extends Component
*/
class PasswordForm extends Component<Props, State> {
/**
* Implements React's {@link Component#getDerivedStateFromProps()}.
*
* @inheritdoc
*/
static getDerivedStateFromProps(props, state) {
return {
enteredPassword: props.editEnabled ? state.enteredPassword : ''
};
}
state = {
enteredPassword: ''
};
@ -74,19 +85,6 @@ class PasswordForm extends Component<Props, State> {
this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
}
/**
* Implements React's {@link Component#componentWillReceiveProps()}. Invoked
* before this mounted component receives new props.
*
* @inheritdoc
* @param {Props} nextProps - New props component will receive.
*/
componentWillReceiveProps(nextProps: Props) {
if (this.props.editEnabled && !nextProps.editEnabled) {
this.setState({ enteredPassword: '' });
}
}
/**
* Implements React's {@link Component#render()}.
*
@ -182,5 +180,4 @@ class PasswordForm extends Component<Props, State> {
}
}
export default translate(PasswordForm);