Skip to content

Commit ae7c592

Browse files
committed
Note that route object contains pure functions
1 parent 8b8b073 commit ae7c592

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

versioned_docs/version-7.x/custom-routers.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ The router is responsible for handling actions dispatched by calling methods on
1111
You can make your own router by building an object with the following functions:
1212

1313
- `type` - String representing the type of the router, e.g. `'stack'`, `'tab'`, `'drawer'` etc.
14-
- `getInitialState` - Function which returns the initial state for the navigator. Receives an options object with `routeNames` and `routeParamList` properties.
15-
- `getRehydratedState` - Function which rehydrates the full [navigation state](navigation-state.md) from a given partial state. Receives a partial state object and an options object with `routeNames` and `routeParamList` properties.
16-
- `getStateForRouteNamesChange` - Function which takes the current state and updated list of route names, and returns a new state. Receives the state object and an options object with `routeNames` and `routeParamList` properties.
17-
- `getStateForAction` - function which takes the current state and action along with an options object with `routeNames` and `routeParamList` properties, and returns a new state. If the action cannot be handled, it should return `null`.
18-
- `getStateForRouteFocus` - Function which takes the current state and key of a route, and returns a new state with that route focused.
19-
- `shouldActionChangeFocus` - Function which determines whether the action should also change focus in parent navigator. Some actions such as `NAVIGATE` can change focus in the parent.
14+
- `getInitialState` - Function that returns the initial state for the navigator. Receives an options object with `routeNames` and `routeParamList` properties.
15+
- `getRehydratedState` - Function that rehydrates the full [navigation state](navigation-state.md) from a given partial state. Receives a partial state object and an options object with `routeNames` and `routeParamList` properties.
16+
- `getStateForRouteNamesChange` - Function that takes the current state and updated list of route names, and returns a new state. Receives the state object and an options object with `routeNames` and `routeParamList` properties.
17+
- `getStateForAction` - Reducer function that takes the current state and action along with an options object with `routeNames` and `routeParamList` properties, and returns a new state. If the action cannot be handled, it should return `null`.
18+
- `getStateForRouteFocus` - Function that takes the current state and key of a route, and returns a new state with that route focused.
19+
- `shouldActionChangeFocus` - Function that determines whether the action should also change focus in parent navigator. Some actions such as `NAVIGATE` can change focus in the parent.
2020
- `actionCreators` - Optional object containing a list of action creators, such as `push`, `pop` etc. These will be used to add helper methods to the `navigation` object to dispatch those actions.
2121

22+
:::info
23+
24+
The functions in the router object should be pure functions, i.e. they should not have any side-effects, mutate parameters or external variables, and should return the same output for the same input.
25+
26+
:::
27+
2228
Example:
2329

2430
```js

0 commit comments

Comments
 (0)