From e9b2518f8adcca033cc8c6d5f689d2a51b74d5f9 Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Sun, 28 Oct 2018 19:10:51 -0700 Subject: [PATCH] ref(info): use getDerivedStateFromProps to update state --- .../components/info-dialog/InfoDialog.web.js | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/react/features/invite/components/info-dialog/InfoDialog.web.js b/react/features/invite/components/info-dialog/InfoDialog.web.js index 9ae652c46..dbb7b1fcb 100644 --- a/react/features/invite/components/info-dialog/InfoDialog.web.js +++ b/react/features/invite/components/info-dialog/InfoDialog.web.js @@ -112,6 +112,28 @@ type State = { class InfoDialog extends Component { _copyElement: ?Object; + /** + * Implements React's {@link Component#getDerivedStateFromProps()}. + * + * @inheritdoc + */ + static getDerivedStateFromProps(props, state) { + let phoneNumber = state.phoneNumber; + + if (!state.phoneNumber && props.dialIn.numbers) { + const { defaultCountry, numbers } = props.dialIn; + + phoneNumber = _getDefaultPhoneNumber(numbers, defaultCountry); + } + + return { + // Exit edit mode when a password is set locally or remotely. + passwordEditEnabled: state.passwordEditEnabled && props._password + ? false : state.passwordEditEnabled, + phoneNumber + }; + } + /** * {@code InfoDialog} component's local state. * @@ -162,28 +184,6 @@ class InfoDialog extends Component { this._setCopyElement = this._setCopyElement.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) { - if (!this.props._password && nextProps._password) { - this.setState({ passwordEditEnabled: false }); - } - - if (!this.state.phoneNumber && nextProps.dialIn.numbers) { - const { defaultCountry, numbers } = nextProps.dialIn; - - this.setState({ - phoneNumber: - _getDefaultPhoneNumber(numbers, defaultCountry) - }); - } - } - /** * Implements React's {@link Component#render()}. *