Skip to content

Commit 0b5138a

Browse files
committed
Improve navigation state docs
1 parent e97ae0c commit 0b5138a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

versioned_docs/version-5.x/navigation-state.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ It's a JavaScript object which looks like this:
1010

1111
```js
1212
const state = {
13+
type: 'stack',
1314
key: 'stack-1',
1415
routeNames: ['Home', 'Profile', 'Settings'],
1516
routes: [
@@ -23,11 +24,12 @@ const state = {
2324

2425
There are few properties present in every navigation state object:
2526

27+
- `type` - Type of the navigator that the state belongs to, e.g. `stack`, `tab`, `drawer`.
2628
- `key` - Unique key to identify the navigator.
2729
- `routeName` - Name of the screens defined in the navigator. This is an unique array containing strings for each screen.
28-
- `routes` - List of route objects (screens) which are rendered in the navigator. It also represents the history in a stack navigator.
30+
- `routes` - List of route objects (screens) which are rendered in the navigator. It also represents the history in a stack navigator. There should be at least one item present in this array.
2931
- `index` - Index of the focused route object in the `routes` array.
30-
- `history` - A list of visited items. This is an optional property and not present in all navigators. For example, it's only present in tab and drawer navigators in the core. The shape of the items in the `history` array can vary depending on the navigator.
32+
- `history` - A list of visited items. This is an optional property and not present in all navigators. For example, it's only present in tab and drawer navigators in the core. The shape of the items in the `history` array can vary depending on the navigator. There should be at least one item present in this array.
3133
- `stale` - A navigation state is assumed to be stale unless the `stale` property is explicitly set to `false`. This means that the state object needs to be ["rehydrated"](#partial-state-objects).
3234

3335
Each route object in a `routes` array may contain the following properties:
@@ -41,6 +43,7 @@ For example, a stack navigator containing a tab navigator nested inside it's hom
4143

4244
```js
4345
const state = {
46+
type: 'stack',
4447
key: 'stack-1',
4548
routeNames: ['Home', 'Profile', 'Settings'],
4649
routes: [
@@ -82,6 +85,7 @@ After rehydration, it'll look something like this:
8285

8386
```js
8487
const state = {
88+
type: 'stack',
8589
key: 'stack-1',
8690
routeNames: ['Home', 'Profile', 'Settings'],
8791
routes: [
@@ -97,4 +101,6 @@ Here, React Navigation filled in the missing bits such as keys, route names, ind
97101

98102
It's also possible to provide invalid data such as non-existent screens and it'll be fixed automatically. While it's not recommended to write code with invalid state objects, it can be super useful if you do things like [state persistence](state-persistence.md), where the configured screens might have changed after an update, which could cause problems if React Navigation didn't fix the state object automatically.
99103

104+
> If you want React Navigation to fix invalid state, you need to make sure that you don't have `stale: false` in the state object. State objects with `stale: false` are assumed to be valid state objects and React Navigation won't attempt to fix them.
105+
100106
When you're providing a state object in [`initialState`](navigation-container.md#initial-state), React Navigation will always assume that it's a stale state object, which makes sure that things like state persistence work smoothly without extra manipulation of the state object.

0 commit comments

Comments
 (0)