mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 12:55:21 +08:00
Updated the reducer (#431)
When the drawer opens / close, the result of AppNavigator.router.getStateForAction(action, state); is null. So the nav state in the store is null which causes errors. This solves that.
This commit is contained in:
@@ -7,10 +7,13 @@ With redux, your app's state is defined by a reducer. Each navigation router eff
|
||||
```
|
||||
const AppNavigator = StackNavigator(AppRouteConfigs);
|
||||
|
||||
const navReducer = (state, action) => {
|
||||
const newState = AppNavigator.router.getStateForAction(action, state);
|
||||
return newState || state;
|
||||
};
|
||||
|
||||
const appReducer = combineReducers({
|
||||
nav: (state, action) => (
|
||||
AppNavigator.router.getStateForAction(action, state)
|
||||
),
|
||||
navReducer,
|
||||
...
|
||||
});
|
||||
|
||||
@@ -55,4 +58,4 @@ const AppNavigator = StackNavigator({
|
||||
});
|
||||
```
|
||||
|
||||
In this case, once you `connect` `AppNavigator` to Redux as is done in `AppWithNavigationState`, `MyTabNavigator` will automatically have access to navigation state as a `navigation` prop.
|
||||
In this case, once you `connect` `AppNavigator` to Redux as is done in `AppWithNavigationState`, `MyTabNavigator` will automatically have access to navigation state as a `navigation` prop.
|
||||
|
||||
Reference in New Issue
Block a user