Skip to content

Commit 92e668e

Browse files
committed
Update troubleshooting guide
1 parent ae7c592 commit 92e668e

File tree

1 file changed

+23
-56
lines changed

1 file changed

+23
-56
lines changed

versioned_docs/version-7.x/troubleshooting.md

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ If it's missing these extensions, add them and then clear metro cache as shown i
6565
6666
## I'm getting "SyntaxError in @react-navigation/xxx/xxx.tsx" or "SyntaxError: /xxx/@react-navigation/xxx/xxx.tsx: Unexpected token"
6767
68-
This might happen if you have an old version of the `metro-react-native-babel-preset` package. Try upgrading it to the latest version.
68+
This might happen if you have an old version of the `@react-native/babel-preset` package. Try upgrading it to the latest version.
6969
7070
```bash npm2yarn
71-
npm install --save-dev metro-react-native-babel-preset
71+
npm install --save-dev @react-native/babel-preset
7272
```
7373
7474
If you have `@babel/core` installed, also upgrade it to latest version.
@@ -77,7 +77,7 @@ If you have `@babel/core` installed, also upgrade it to latest version.
7777
npm install --save-dev @babel/core
7878
```
7979
80-
If upgrading the packages don't help, you can also try deleting your `node_modules` as well as lock the file and reinstall your dependencies.
80+
If upgrading the packages don't help, you can also try deleting your `node_modules` and then the lock the file and reinstall your dependencies.
8181
8282
If you use `npm`:
8383
@@ -95,6 +95,12 @@ rm yarn.lock
9595
yarn
9696
```
9797
98+
:::warning
99+
100+
Deleting the lockfile is generally not recommended as it may upgrade your dependencies to versions that haven't been tested with your project. So only use this as a last resort.
101+
102+
:::
103+
98104
After upgrading or reinstalling the packages, you should also clear Metro bundler's cache following the instructions earlier in the page.
99105
100106
## I'm getting "Module '[...]' has no exported member 'xxx' when using TypeScript
@@ -215,6 +221,7 @@ const Navigation = createStaticNavigation(RootStack);
215221
216222
export default function App() {
217223
return (
224+
// highlight-next-line
218225
<View style={{ flex: 1 }}>
219226
<Navigation />
220227
</View>
@@ -232,6 +239,7 @@ import { NavigationContainer } from '@react-navigation/native';
232239
233240
export default function App() {
234241
return (
242+
// highlight-next-line
235243
<View style={{ flex: 1 }}>
236244
<NavigationContainer>{/* ... */}</NavigationContainer>
237245
</View>
@@ -278,6 +286,7 @@ const Stack = createNativeStackNavigator({
278286
Home: {
279287
screen: Home,
280288
options: {
289+
// highlight-next-line
281290
headerTitle: (props) => <MyTitle {...props} />,
282291
},
283292
},
@@ -292,7 +301,10 @@ const Stack = createNativeStackNavigator({
292301
<Stack.Screen
293302
name="Home"
294303
component={Home}
295-
option={{ headerTitle: (props) => <MyTitle {...props} /> }}
304+
option={{
305+
// highlight-next-line
306+
headerTitle: (props) => <MyTitle {...props} />,
307+
}}
296308
/>
297309
```
298310
@@ -311,6 +323,7 @@ const Stack = createNativeStackNavigator({
311323
screen: Home,
312324
options: {
313325
// This is not correct
326+
// highlight-next-line
314327
headerTitle: MyTitle,
315328
},
316329
},
@@ -327,6 +340,7 @@ const Stack = createNativeStackNavigator({
327340
component={Home}
328341
option={{
329342
// This is not correct
343+
// highlight-next-line
330344
headerTitle: MyTitle,
331345
}}
332346
/>
@@ -343,28 +357,6 @@ Sometimes you might have noticed that your screens unmount/remount, or your loca
343357
344358
The simplest example is something like following:
345359
346-
<Tabs groupId="config" queryString="config">
347-
<TabItem value="static" label="Static" default>
348-
349-
```js
350-
const RootStack = createNativeStackNavigator({
351-
screens: {
352-
Home: () => {
353-
return <SomeComponent />;
354-
},
355-
},
356-
});
357-
358-
const Navigation = createStaticNavigation(RootStack);
359-
360-
function App() {
361-
return <Navigation />;
362-
}
363-
```
364-
365-
</TabItem>
366-
<TabItem value="dynamic" label="Dynamic">
367-
368360
```js
369361
function App() {
370362
return (
@@ -380,9 +372,6 @@ function App() {
380372
}
381373
```
382374
383-
</TabItem>
384-
</Tabs>
385-
386375
The `component` prop expects a React Component, but in the example, it's getting a function returning an React Element. While superficially a component and a function returning a React Element look the exact same, they don't behave the same way when used.
387376
388377
Here, every time the component re-renders, a new function will be created and passed to the `component` prop. React will see a new component and unmount the previous component before rendering the new one. This will cause any local state in the old component to be lost. React Navigation will detect and warn for this specific case but there can be other ways you might be creating components during render which it can't detect.
@@ -432,30 +421,6 @@ function App() {
432421
433422
Or when you use a higher order component (such as `connect` from Redux, or `withX` functions that accept a component) inside another component:
434423
435-
<Tabs groupId="config" queryString="config">
436-
<TabItem value="static" label="Static" default>
437-
438-
```js
439-
function App() {
440-
const Home = () => {
441-
return <SomeComponent />;
442-
};
443-
444-
const RootStack = createNativeStackNavigator({
445-
screens: {
446-
Home: withSomeData(Home),
447-
},
448-
});
449-
450-
const Navigation = createStaticNavigation(RootStack);
451-
452-
return <Navigation />;
453-
}
454-
```
455-
456-
</TabItem>
457-
<TabItem value="dynamic" label="Dynamic">
458-
459424
```js
460425
function App() {
461426
return (
@@ -466,15 +431,15 @@ function App() {
466431
}
467432
```
468433
469-
</TabItem>
470-
</Tabs>
471-
472434
If you're unsure, it's always best to make sure that the components you are using as screens are defined outside of a React component. They could be defined in another file and imported, or defined at the top level scope in the same file:
435+
473436
<Tabs groupId="config" queryString="config">
474437
<TabItem value="static" label="Static" default>
475438
476439
```js
477440
const Home = () => {
441+
// ...
442+
478443
return <SomeComponent />;
479444
};
480445
@@ -496,6 +461,8 @@ function App() {
496461
497462
```js
498463
const Home = () => {
464+
// ...
465+
499466
return <SomeComponent />;
500467
};
501468

0 commit comments

Comments
 (0)