expo / ex-navigation

Route-centric navigation for React Native
997 stars 201 forks source link

Cannot read property 'getRoute' of undefined - when integrating with redux #443

Closed robbykim closed 7 years ago

robbykim commented 7 years ago

I'm trying to integrate redux with the navigator and getting an error saying Cannot read property 'getRoute' of undefined when I run the app. The following is my navigationContext (taken from the example):

const navigationContext = new NavigationContext({
  router: Router,
  store: Store,
});

My store:

The reducers are combined in my reducers.js file and exported from there so the navigation: NavigationReducer is accounted for.

const createStoreWithNavigation = createNavigationEnabledStore({
  createStore,
  navigationStateKey: 'navigation',
});

const store = createStoreWithNavigation(
  combineReducers({
    navigation: NavigationReducer,
    // my other reducers,
  }),
);

export default store;

My index.js:

<Provider store={store}>
  <View style={styles.container}>
     <NavigationProvider context={navigationContext}>
       <StackNavigation
         id="root"
         initialRoute={Router.getRoute('rootNavigation')}
       />
    </NavigationProvider>
  </View>
</Provider>

When I replace the context={navigationContext} with the old router={Router}, it works fine. I guess I'm doing something wrong with the navigationContext but am not sure what it is. From what I understand, a context is needed in order to hold the navigation in the store. Any suggestions would be much appreciated