Skip to content

Instantly share code, notes, and snippets.

@shubhnik
shubhnik / navigationReducer.js
Last active January 15, 2018 10:45
Our new navigationReducer capable of handling authentication flow.
// Don't forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation/tree/authFlow
import { NavigationActions } from "react-navigation";
// AppNavigator is the one defined in the start of PART-2 of this blog --> https://medium.com/@shubhnik/a-comprehensive-guide-for-integrating-react-navigation-with-redux-including-authentication-flow-cb7b90611adf
const ActionForLoggedOut = AppNavigator.router.getActionForPathAndParams("login");
const ActionForLoggedIn = AppNavigator.router.getActionForPathAndParams("screen1");
const stateForLoggedOut = AppNavigator.router.getStateForAction(ActionForLoggedOut);
const stateForLoggedIn = AppNavigator.router.getStateForAction(ActionForLoggedIn);
const initialState = { stateForLoggedOut, stateForLoggedIn };