ref(welcome-page): use getDerivedStateFromProps, set mounted after actual mount
This commit is contained in:
parent
e0cbb838be
commit
45068f68db
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue