react-navigation / redux-helpers

Redux middleware and utils for React Navigation
Other
296 stars 43 forks source link

TypeError: Cannot read property 'router' of undefined #52

Closed DragonSpirit closed 6 years ago

DragonSpirit commented 6 years ago

Hello! I get following issue.

My code ```javascript // middleware part middlewares.push(createReactNavigationReduxMiddleware( 'root', state => state.getIn(['navigation']), )) const RootNavigator = createStackNavigator(AppRouteConfigs) const AppWithNavigationState = reduxifyNavigator(RootNavigator, 'root') class ReduxNavigation extends React.Component { render() { const { dispatch, navigation, language, theme, } = this.props return ( ) } const _getSceneKey = state => { const nav = state.get('navigation') const lastItem = nav && nav.routes && nav.routes.slice(-1)[0] return lastItem && lastItem.routeName } const mapStateToProps = state => { const sceneKey = _getSceneKey(state) return { navigation: state.getIn(['navigation']), language: getLocalization(state), sceneKey, theme: getTheme(state, 'Theme', ''), } } const mapDispatchToProps = dispatch => ({ dispatch, }) export const AppNavigator = connect(mapStateToProps, mapDispatchToProps)(ReduxNavigation) // Entry point export default class App extends React.PureComponent { constructor(props) { super(props) } render() { return ( ) } } ```

Error appears in render method of NavigatorReduxWrapper.
"Navigator" is undefined.
Did I do something wrong?

"react-navigation": "^2.3.1", same with "2.7.0"
"react-navigation-redux-helpers": "^2.0.2"
Ashoat commented 6 years ago

Which one is NavigatorReduxWrapper? I can look at this today if you put it in an Expo Snack!

DragonSpirit commented 6 years ago

Here, in library. I will try to reproduce it with Expo Snack.

Ashoat commented 6 years ago

It appears that you are passing an undefined navigator to reduxifyNavigator?

DragonSpirit commented 6 years ago

Well, I solved this issue. You was right. It happens due to race condition in import/export. I just refactored my code and got rid of this error. Anyway thanks for help!