myT*_*oro 7 react-native redux react-redux react-navigation
我正在学习React Native和Redux,我已经开始使用第三方库 - 特别是React Navigation
我已经按照Dan Parker的中级教程的教程,我仍然无法使它工作
我的应用程序的RootContainer:
<PrimaryNavigation />
...
export default connect(null, mapDispatchToProps)(RootContainer)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
我的创建商店:
const rootReducer = combineReducers({
...
primaryNav: require('../Navigation/AppNavigation').reducer
})
return configureStore(rootReducer, rootSaga)
Run Code Online (Sandbox Code Playgroud)
我得到一个错误:
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'
到目前为止我的理解是:
我错过了初始状态吗?我没有正确地将它连接到Redux吗?我是否需要启动发送才能进入第一个屏幕?
谢谢
小智 1
我认为您的代码组织中缺少一些东西。
这是我扩展 Tyler Mcginnis 完成的 github 笔记应用程序的努力。我更新了代码以支持最新版本的 React 和 React Native,我还扩展了应用程序以使用支持 iOS 和 Android 的 React-navigation。我添加了 Redux 来管理存储,并使用 Redux-Sagas 来处理异步数据获取。
https://github.com/ahmedkamohamed/react-native-navigation-redux-sagas
| 归档时间: |
|
| 查看次数: |
2629 次 |
| 最近记录: |