Skip to content

Commit 82d7c4c

Browse files
committed
Add workaround for bug in Linking.getInitialUrl
1 parent f654a43 commit 82d7c4c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

website/versioned_docs/version-5.x/deep-linking.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,17 @@ function App() {
5252
const [initialState, setInitialState] = React.useState();
5353

5454
React.useEffect(() => {
55-
getInitialState()
56-
.catch(() => {})
55+
Promise.race(
56+
getInitialState(),
57+
new Promise(resolve =>
58+
// Timeout in 150ms if `getInitialState` doesn't resolve
59+
// Workaround for https://github.com/facebook/react-native/issues/25675
60+
setTimeout(resolve, 150)
61+
)
62+
)
63+
.catch(e => {
64+
console.error(e);
65+
})
5766
.then(state => {
5867
if (state !== undefined) {
5968
setInitialState(state);
@@ -75,6 +84,8 @@ function App() {
7584
}
7685
```
7786

87+
> Note: The `getInitialState` function uses React Native's `Linking.getInitialUrl()` under the hood. Currently there seems to be bug ([facebook/react-native#25675](https://github.com/facebook/react-native/issues/25675)) which results in it never resolving on Android.
88+
7889
Often, directly translating path segments to route names may not be the expected behavior. For example, you might want to parse the path `/feed/latest` to something like:
7990

8091
```js

0 commit comments

Comments
 (0)