Selaa lähdekoodia

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

master
Leonard Kim 7 vuotta sitten
vanhempi
commit
45068f68db
1 muutettua tiedostoa jossa 14 lisäystä ja 14 poistoa
  1. 14
    14
      react/features/welcome/components/AbstractWelcomePage.js

+ 14
- 14
react/features/welcome/components/AbstractWelcomePage.js Näytä tiedosto

@@ -37,6 +37,17 @@ type Props = {
37 37
 export class AbstractWelcomePage extends Component<Props, *> {
38 38
     _mounted: ?boolean;
39 39
 
40
+    /**
41
+     * Implements React's {@link Component#getDerivedStateFromProps()}.
42
+     *
43
+     * @inheritdoc
44
+     */
45
+    static getDerivedStateFromProps(props: Props, state: Object) {
46
+        return {
47
+            room: props._room || state.room
48
+        };
49
+    }
50
+
40 51
     /**
41 52
      * Save room name into component's local state.
42 53
      *
@@ -77,26 +88,15 @@ export class AbstractWelcomePage extends Component<Props, *> {
77 88
     }
78 89
 
79 90
     /**
80
-     * Implements React's {@link Component#componentWillMount()}. Invoked
81
-     * immediately before mounting occurs.
91
+     * Implements React's {@link Component#componentDidMount()}. Invoked
92
+     * immediately after mounting occurs.
82 93
      *
83 94
      * @inheritdoc
84 95
      */
85
-    componentWillMount() {
96
+    componentDidMount() {
86 97
         this._mounted = true;
87 98
     }
88 99
 
89
-    /**
90
-     * Implements React's {@link Component#componentWillReceiveProps()}. Invoked
91
-     * before this mounted component receives new props.
92
-     *
93
-     * @inheritdoc
94
-     * @param {Props} nextProps - New props component will receive.
95
-     */
96
-    componentWillReceiveProps(nextProps: Props) {
97
-        this.setState({ room: nextProps._room });
98
-    }
99
-
100 100
     /**
101 101
      * Implements React's {@link Component#componentWillUnmount()}. Invoked
102 102
      * immediately before this component is unmounted and destroyed.

Loading…
Peruuta
Tallenna