【问题标题】:React Native Navigation with Redux, how to use?React Native Navigation with Redux,如何使用?
【发布时间】:2019-01-20 06:16:00
【问题描述】:

网上有一些教程介绍了如何在 Redux 中使用 react-native-navigation。但是,它们都不完整,我真的不明白我需要在我的根函数中返回什么。

如果我真的回来了

<Provider store={mystore}>
<MainScreen />
</Provider>

那么,为什么需要使用registerComponentWithRedux? 如果我使用registerComponentWithRedux,那么我希望不必再次用提供者包装我的组件。

任何人都可以澄清这一点,或者有人知道带有registerComponentWithRedux 的 react-native-navigation 的完整工作示例吗?

如前所述,我在网上看到了很多教程,但没有具体说明应用程序的入口文件中返回的内容。

【问题讨论】:

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


    【解决方案1】:

    registerComponentWithRedux() 已被弃用,取而代之的是 Registering screens with wrapping provider component。

    您提供的代码示例实际上是正确的方法,因为 registerComponentWithRedux 函数已被弃用。使用 redux 注册屏幕看起来像这样 (sample from RNN docs):

    Navigation.registerComponent('navigation.playground.ReduxScreen', () => (props) => (
      <Provider store={reduxStore}>
        <ReduxScreen {...props} />
      </Provider>
    ), () => ReduxScreen);
    

    【讨论】:

      【解决方案2】:

      正如 React Native Navigation -Version2 的文档所述,使用 Redux 注册组件如下:

      Navigation.registerComponent('WelcomeComponentScreen', () => (props) => (
        <Provider store={reduxStore}>
          <'WelcomeComponentScreen' {...props} />
        </Provider>
      ), () => 'WelcomeComponentScreen');

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-23
        • 2018-11-14
        • 2017-11-28
        • 1970-01-01
        • 2019-10-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多