ref(app): set url prop to state in componentDidUpdate

This is done to kill off the last deprecated lifecycle
usage. There is special logic within index.native to get a
default meeting url by asynchronously fetching it, if
a url is not passed initially. The url is then put onto
state and overridable on subsequent prop updates.
This commit is contained in:
Leonard Kim 2019-01-04 21:08:15 -08:00 committed by Saúl Ibarra Corretgé
parent 5c0ae10ccb
commit 29809ab024
1 changed files with 13 additions and 3 deletions

View File

@ -103,15 +103,25 @@ class Root extends Component<Props, State> {
}
/**
* Implements React's {@link Component#componentWillReceiveProps()}.
* Implements React's {@link Component#componentDidUpdate()}.
*
* New props can be set from the native side by setting the appProperties
* property (on iOS) or calling setAppProperties (on Android).
*
* @inheritdoc
*/
componentWillReceiveProps({ url }) {
equals(this.props.url, url) || this.setState({ url: url || null });
componentDidUpdate(prevProps, prevState) {
// Ignore the special state update triggered on {@code Root}
// instantiation where an undefined url prop is set to a default.
if (typeof prevState.url === 'undefined'
&& typeof this.state.url !== 'undefined') {
return;
}
if (!equals(prevProps.url, this.props.url)) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ url: this.props.url || null });
}
}
/**