首页 > 解决方案 > 用redux反应导航不起作用

问题描述

我想从我的动作 js 文件中更改路由,所以结合到根 Reducer 的 navReducer.js 是

const router = RootStack.router;
const initialState = router.getStateForAction(NavigationActions.init());

export default navReducer = (state = initialState, action) => {
  return router.getStateForAction(action, state);

}

而连接到reducer的mainRoute.js是

const SiraRoute = (props) => (
    <RootStack navigation={{
            dispatch: props.dispatch,
            state: props.nav,
        }} 
    />
)

const mapStateToProps = (state) => ({
    nav: state.navReducer,
});

export default connect(mapStateToProps)(SiraRoute);

index.js 文件是

const store = configureStore();

const sira = () => (
  <Provider store={store}>
    <SiraRoute  />
  </Provider>
)

AppRegistry.registerComponent('SIRA', () => sira);

但我得到navigation.getChildNavigation 不是函数错误。

标签: reactjsreact-nativeredux

解决方案


这可能与 React Navigation 正在放弃对 redux 的支持有关。

反应导航文档:

警告:在 2018 年秋季发布的下一个主要版本的 React Navigation 中,我们将不再提供有关如何与 Redux 集成的任何信息,并且它可能会停止工作。

关于如何在反应导航中从 Redux 迁移的讨论: https ://github.com/react-navigation/react-navigation/issues/4490


推荐阅读