Skip to content

Instantly share code, notes, and snippets.

@shubhnik
Last active November 10, 2017 12:12
Show Gist options
  • Save shubhnik/b55602633aaeb5919f6f3c15552d1802 to your computer and use it in GitHub Desktop.
Save shubhnik/b55602633aaeb5919f6f3c15552d1802 to your computer and use it in GitHub Desktop.
Only a basic navigation reducer
// Don not forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation
// The particular navigationReducer here ---> https://github.com/shubhnik/redux-react-navigation/blob/master/src/Reducers/navigationReducer.js
const AppNavigator = StackNavigator({
screen1: {
screen: Screen1
},
screen2: {
screen: Screen2
}
});
// We set the initial state of the navigator to route "screen1", i.e screen1 will be displayed first.
const initialState = AppNavigator.router.getStateForAction(AppNavigator.router.getActionForPathAndParams('screen1'))
const navigationReducer = (state = initialState, action) => {
// **action** will be of type: {"type": "Navigation/NAVIGATE", "routeName": SOME_ROUTE}
// gets the new updated state of the navigator (previous state + new route), will return null if the action is not understandable.
const newState = AppNavigator.router.getStateForAction(action, state)
// return newState or previous state if newState is null
return newState || state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment