ref(welcome-page): use getDerivedStateFromProps, set mounted after actual mount

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

View File

@ -37,6 +37,17 @@ type Props = {
export class AbstractWelcomePage extends Component<Props, *> {
_mounted: ?boolean;
/**
* Implements React's {@link Component#getDerivedStateFromProps()}.
*
* @inheritdoc
*/
static getDerivedStateFromProps(props: Props, state: Object) {
return {
room: props._room || state.room
};
}
/**
* Save room name into component's local state.
*
@ -77,26 +88,15 @@ export class AbstractWelcomePage extends Component<Props, *> {
}
/**
* Implements React's {@link Component#componentWillMount()}. Invoked
* immediately before mounting occurs.
* Implements React's {@link Component#componentDidMount()}. Invoked
* immediately after mounting occurs.
*
* @inheritdoc
*/
componentWillMount() {
componentDidMount() {
this._mounted = true;
}
/**
* 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) {
this.setState({ room: nextProps._room });
}
/**
* Implements React's {@link Component#componentWillUnmount()}. Invoked
* immediately before this component is unmounted and destroyed.