You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/troubleshooting.md
+180Lines changed: 180 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,9 @@ title: Troubleshooting
4
4
sidebar_label: Troubleshooting
5
5
---
6
6
7
+
import Tabs from '@theme/Tabs';
8
+
import TabItem from '@theme/TabItem';
9
+
7
10
This section attempts to outline issues that users frequently encounter when first getting accustomed to using React Navigation. These issues may or may not be related to React Navigation itself.
8
11
9
12
Before troubleshooting an issue, make sure that you have upgraded to **the latest available versions** of the packages. You can install the latest versions by installing the packages again (e.g. `npm install package-name`).
@@ -198,6 +201,30 @@ Now rebuild the app and test on your device or simulator.
198
201
199
202
If you wrap the container in a `View`, make sure the `View` stretches to fill the container using `flex: 1`:
200
203
204
+
<Tabs groupId="config" queryString="config">
205
+
<TabItem value="static" label="Static" default>
206
+
207
+
```js
208
+
import * as React from 'react';
209
+
import { View } from 'react-native';
210
+
import { createStaticNavigation } from '@react-navigation/native';
@@ -212,6 +239,9 @@ export default function App() {
212
239
}
213
240
```
214
241
242
+
</TabItem>
243
+
</Tabs>
244
+
215
245
## I get the warning "Non-serializable values were found in the navigation state"
216
246
217
247
This can happen if you are passing non-serializable values such as class instances, functions etc. in params. React Navigation warns you in this case because this can break other functionality such [state persistence](state-persistence.md), [deep linking](deep-linking.md) etc.
@@ -239,6 +269,25 @@ LogBox.ignoreLogs([
239
269
240
270
This can happen when you pass a React component to an option that accepts a functionreturning a react element. For example, the [`headerTitle` option in native stack navigator](native-stack-navigator.md#headerTitle) expects a functionreturning a react element:
241
271
272
+
<Tabs groupId="config" queryString="config">
273
+
<TabItem value="static" label="Static" default>
274
+
275
+
```js
276
+
const Stack = createNativeStackNavigator({
277
+
screens: {
278
+
Home: {
279
+
screen: Home,
280
+
options: {
281
+
headerTitle: (props) =><MyTitle {...props} />,
282
+
},
283
+
},
284
+
},
285
+
});
286
+
```
287
+
288
+
</TabItem>
289
+
<TabItem value="dynamic" label="Dynamic" default>
290
+
242
291
```js
243
292
<Stack.Screen
244
293
name="Home"
@@ -247,8 +296,31 @@ This can happen when you pass a React component to an option that accepts a func
247
296
/>
248
297
```
249
298
299
+
</TabItem>
300
+
</Tabs>
301
+
250
302
If you directly pass a functionhere, you'll get this error when using hooks:
251
303
304
+
<Tabs groupId="config" queryString="config">
305
+
<TabItem value="static" label="Static" default>
306
+
307
+
```js
308
+
const Stack = createNativeStackNavigator({
309
+
screens: {
310
+
Home: {
311
+
screen: Home,
312
+
options: {
313
+
// This is not correct
314
+
headerTitle: MyTitle,
315
+
},
316
+
},
317
+
},
318
+
});
319
+
```
320
+
321
+
</TabItem>
322
+
<TabItem value="dynamic" label="Dynamic" default>
323
+
252
324
```js
253
325
<Stack.Screen
254
326
name="Home"
@@ -260,6 +332,9 @@ If you directly pass a function here, you'll get this error when using hooks:
260
332
/>
261
333
```
262
334
335
+
</TabItem>
336
+
</Tabs>
337
+
263
338
The same applies to other options like `headerLeft`, `headerRight`, `tabBarIcon` etc. as well as props such as `tabBar`, `drawerContent` etc.
264
339
265
340
## Screens are unmounting/remounting during navigation
@@ -268,6 +343,28 @@ Sometimes you might have noticed that your screens unmount/remount, or your loca
The `component` prop expects a React Component, but in the example, it's getting a functionreturning an React Element. While superficially a component and a functionreturning a React Element look the exact same, they don't behave the same way when used.
287
387
288
388
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.
289
389
290
390
Another easy to identify example of this is when you create a component inside another component:
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:
This is not React Navigation specific, but related to React in general. You should always avoid creating components during render, whether you are using React Navigation or not.
335
515
336
516
## App is not working properly when connected to Chrome Debugger
0 commit comments