我學習陣營本地和終極版,我已經使用第三方庫開始 - 特別是React Navigation陣營導航Redux的國家管理
我跟着它Dan Parker's Medium Tutorial的教程,我仍然不能得到它工作
我的應用程序的RootContainer:
<PrimaryNavigation />
...
export default connect(null, mapDispatchToProps)(RootContainer)
PrimaryNavigation定義:
const mapStateToProps = (state) => {
return {
navigationState: state.primaryNav
}
}
class PrimaryNavigation extends React.Component {
render() {
return (
<PrimaryNav
navigation={
addNavigationHelpers({
dispatch: this.props.dispatch,
state: this.props.navigationState
})
}
/>
)
}
}
export default connect(mapStateToProps)(PrimaryNavigation)
PrimaryNav定義:
const routeConfiguration = {
LoginScreen: {
screen: LoginScreen
},
MainContainer: {
screen: MainContainer
}
}
const PrimaryNav = StackNavigator(
routeConfiguration,
{
headerMode: 'none'
})
export default PrimaryNav
export const reducer = (state, action) => {
const newState = PrimaryNav.router.getStateForAction(action,state)
return newState || state;
}
我創造店:
const rootReducer = combineReducers({
...
primaryNav: require('../Navigation/AppNavigation').reducer
})
return configureStore(rootReducer, rootSaga)
我得到的線沿線的一個錯誤:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of 'PrimaryNavigation'
我的理解至今是:
- RootContainer被連接到一個存儲 - 它保持PrimaryNavigation
- PrimaryNavigation包含一個導航器(PrimaryNav),它包裝導航並將其傳遞狀態
- PrimaryNav是實際的導航 - 我定義路由和缺省初始化
- ,處理PrimaryNav減速只是PrimaryNav.router.getStateForAction
我缺少初始狀態?我沒有正確連接到Redux嗎?我是否需要啓動派遣才能進入第一個屏幕?
感謝
你需要'PrimaryNav'正常嗎?它回來了'未定義',所以我猜它是一個簡單的要求你的組件失敗 – Trip