首页 > 解决方案 > 将 Redux 与 ReactNavigation 集成时,mapStateToProps() 返回未定义

问题描述

我目前正在处理两个屏幕:Login 和 EmployeeList,并且没有设置 initialRouteName。

我结合了两个减速器:NavReducer 和 AuthReducer。我在 LoginForm 中接收 state.auth,在 RouterWithNavigationState 中接收 state.nav,如下所示:

class RouterWithNavigationState extends Component{
    ...
    <Router navigation = {addNavigationHelpers({
                    dispatch: this.props.dispatch,
                    state: this.props.navigation
                })} />
    ...
    }

    const mapStateToProps = state =>
    {
        console.log (state.nav)
        return 
        {
           navigation: state.nav
        } 
    }
    export default connect(mapStateToProps)(RouterWithNavigationState)


但是我得到一个错误:
(1)mapStateToProps() in Connect(RouterWithNavigationState) must return a plain object. Instead received undefined.
(2)addNavigationHelpers is not a function

日志语句打印我在 NavReducer.js 中定义的初始状态,如下所示:{index: 0, routes: Array(1)}


包.json:
"dependencies": { "firebase": "^4.13.1", "react": "16.3.1", "react-native": "0.55.3", "react-navigation": "^2.0.1", "react-redux": "^5.0.7", "redux": "^4.0.0", "redux-thunk": "^2.2.0" }, "devDependencies": { "babel-jest": "22.4.3", "babel-preset-react-native": "4.0.0", "jest": "22.4.3", "react-test-renderer": "16.3.1" }

我错过了什么?

标签: react-nativereact-reduxreact-navigation

解决方案


推荐阅读