ref(info): derive when to clear the entered password state
This commit is contained in:
parent
c28c70fb2f
commit
e0cbb838be
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue