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:
Angelo
2017-02-22 05:15:30 +01:00
committed by Eric Vicenti
parent 3a1766cb78
commit 8e1b6e9042

View File

@@ -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.