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: docs/state-persistence.md
+31-10Lines changed: 31 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -12,33 +12,52 @@ This is especially valuable during development because it allows the developer t
12
12
13
13
## Usage
14
14
15
-
You can enable persistence for your top-level navigator by rendering it with a `persistenceKey`:
15
+
You can enable persistence for your top-level navigator by rendering it with `persistNavigationState` and `loadNavigationState` props:
16
+
17
+
-`persistNavigationState` is an async function that receives single argument - the navigation state object. The function should persist it.
18
+
-`loadNavigationState` is an async function that does the inverse - it should load the persisted navigation state and return a Promise that resolves with the navigation state object. If the function rejects, React Navigation will start as if no state was provided.
Because the state is persisted asynchronously, the app must render an empty/loading view for a moment while the `AsyncStorage` request completes. To customize the loading view that is rendered during this time, you can use the `renderLoadingExperimental` prop:
55
+
Because the state is loaded asynchronously, the app must render an empty/loading view for a moment before the `loadNavigationState` function returns. To customize the loading view that is rendered during this time, you can use the `renderLoadingExperimental` prop:
@@ -47,7 +66,9 @@ Because the state is persisted asynchronously, the app must render an empty/load
47
66
48
67
## Warning: Serializable State
49
68
50
-
Each param, route, and navigation state must be fully JSON-serializable for this feature to work. This means that your routes and params must contain no functions, class instances, or recursive data structures.
69
+
Each param, route, and navigation state must be fully serializable for this feature to work. Typically, you would serialize the state as a JSON string. This means that your routes and params must contain no functions, class instances, or recursive data structures.
70
+
71
+
If you need to modify the nav state object, you may do so in the `loadNavigationState` / `persistNavigationState` functions, but note that if your `loadNavigationState` provides an invalid object (an object from which the navigation state cannot be recovered), React Navigation may not be able to handle the situation gracefully.
Copy file name to clipboardExpand all lines: website/versioned_docs/version-3.x/state-persistence.md
+31-10Lines changed: 31 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -13,33 +13,52 @@ This is especially valuable during development because it allows the developer t
13
13
14
14
## Usage
15
15
16
-
You can enable persistence for your top-level navigator by rendering it with a `persistenceKey`:
16
+
You can enable persistence for your top-level navigator by rendering it with `persistNavigationState` and `loadNavigationState` props:
17
+
18
+
-`persistNavigationState` is an async function that receives single argument - the navigation state object. The function should persist it.
19
+
-`loadNavigationState` is an async function that does the inverse - it should load the persisted navigation state and return a Promise that resolves with the navigation state object. If the function rejects, React Navigation will start as if no state was provided.
Because the state is persisted asynchronously, the app must render an empty/loading view for a moment while the `AsyncStorage` request completes. To customize the loading view that is rendered during this time, you can use the `renderLoadingExperimental` prop:
56
+
Because the state is loaded asynchronously, the app must render an empty/loading view for a moment before the `loadNavigationState` function returns. To customize the loading view that is rendered during this time, you can use the `renderLoadingExperimental` prop:
@@ -48,7 +67,9 @@ Because the state is persisted asynchronously, the app must render an empty/load
48
67
49
68
## Warning: Serializable State
50
69
51
-
Each param, route, and navigation state must be fully JSON-serializable for this feature to work. This means that your routes and params must contain no functions, class instances, or recursive data structures.
70
+
Each param, route, and navigation state must be fully serializable for this feature to work. Typically, you would serialize the state as a JSON string. This means that your routes and params must contain no functions, class instances, or recursive data structures.
71
+
72
+
If you need to modify the nav state object, you may do so in the `loadNavigationState` / `persistNavigationState` functions, but note that if your `loadNavigationState` provides an invalid object (an object from which the navigation state cannot be recovered), React Navigation may not be able to handle the situation gracefully.
0 commit comments