将Redux与ReactNavigation集成时,mapStateToProps()返回undefined

时间:2018-05-15 12:37:35

标签: react-native react-redux react-navigation

我目前正在处理两个屏幕: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

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


package.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" }

我错过了什么?

0 个答案:

没有答案