【问题标题】:React native props managementReact 原生道具管理
【发布时间】:2020-02-22 14:56:23
【问题描述】:

我在 react-native 中使用 react-native-router-flux 进行导航。

我的标签使用具有不同道具的相同组件。第一个选项卡更改时一切正常,但返回相同选项卡时道具没有更改。

返回同一个标签应该使用什么方法?

App.js

<Scene key="root" hideNavBar={true}>
  <Scene key="rootTabBar" tabs={true} hideNavBar={true}>
    <Scene
      key="firstCaregory"
      title="First Category"
      id={1}
      component={Category}
    />
    <Scene
      key="secondCategory"
      title="Second Category"
      id={2}
      component={Category}
    />
  </Scene>
</Scene>

类别.js

componentDidMount() {
  this.props.fetchNews(this.props.id);
}

【问题讨论】:

    标签: reactjs react-native react-redux react-native-router-flux


    【解决方案1】:

    当您导航到/从屏幕时,请尝试检查您的 Category 组件是否正在卸载。由于您在 componentDidMount 中加载数据,因此您加载数据的唯一时间是为每个场景首次构建组件时。在使用嵌套场景的选项卡的 RNRF 设置中,我可以确认导航不会触发组件卸载,但值得通过在 Category 组件内的 componentWillUnmount 内放置控制台日志来检查您的最终结果。

    选择返回同一选项卡时的方法取决于上述理论是否正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-02
      • 1970-01-01
      • 2021-08-10
      • 2017-02-11
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多