我正在使用 reactnavigation 和 redux 创建一个 react-native 应用程序。
在加载应用程序时,我从 NavContainer 收到以下警告:Warning: Failed prop type: The prop 'navigation.dispatch' is marked as required in 'CardStack', but its value is 'undefined'
当我尝试通过导航导航页面时,这会导致错误,this.props.navigation.navigate('Station');
因为 navigation.dispatch 不是函数
该应用程序有一个 NavContainer ,我猜它缺少一些东西,因为在渲染函数中未定义调度:
import React, { Component } from 'react'
import { addNavigationHelpers } from 'react-navigation'
import AppNavigator from '../lib/navigationConfiguration'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux';
import { ActionCreators } from '../actions';
class NavContainer extends Component {
render(){
const { dispatch, navigationState} = this.props
return (
<AppNavigator
navigation={
addNavigationHelpers({
dispatch: dispatch,
state: navigationState
})
}
/>
)
}
}
function mapStateToProps(state){
return {
navigationState: state.nav
}
}
function mapDispatchToProps(dispatch){
return bindActionCreators(ActionCreators, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(NavContainer)