Browse Source

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.
j8
Leonard Kim 6 years ago
parent
commit
29809ab024
1 changed files with 13 additions and 3 deletions
  1. 13
    3
      react/index.native.js

+ 13
- 3
react/index.native.js View File

@@ -103,15 +103,25 @@ class Root extends Component<Props, State> {
103 103
     }
104 104
 
105 105
     /**
106
-     * Implements React's {@link Component#componentWillReceiveProps()}.
106
+     * Implements React's {@link Component#componentDidUpdate()}.
107 107
      *
108 108
      * New props can be set from the native side by setting the appProperties
109 109
      * property (on iOS) or calling setAppProperties (on Android).
110 110
      *
111 111
      * @inheritdoc
112 112
      */
113
-    componentWillReceiveProps({ url }) {
114
-        equals(this.props.url, url) || this.setState({ url: url || null });
113
+    componentDidUpdate(prevProps, prevState) {
114
+        // Ignore the special state update triggered on {@code Root}
115
+        // instantiation where an undefined url prop is set to a default.
116
+        if (typeof prevState.url === 'undefined'
117
+                && typeof this.state.url !== 'undefined') {
118
+            return;
119
+        }
120
+
121
+        if (!equals(prevProps.url, this.props.url)) {
122
+            // eslint-disable-next-line  react/no-did-update-set-state
123
+            this.setState({ url: this.props.url || null });
124
+        }
115 125
     }
116 126
 
117 127
     /**

Loading…
Cancel
Save