【问题标题】:react-navigation Infinite loop inside componentWillReceivePropsreact-navigation componentWillReceiveProps 内的无限循环
【发布时间】:2017-05-28 11:10:04
【问题描述】:

我有 2 个组件,组件 a 和组件 b

我想在更改状态后从组件 a 导航到组件 b。 当我改变状态时,它会触发我的 componentWillReceiveProps 函数,我从那里导航。

componentWillReceiveProps(nextProps) {
  const { navigate } = nextProps.navigation;
  navigate('b');
}

现在我进入了一个无限循环,它开始一次又一次地触发 componentWillReceiveProps 而不是导航

需要帮助。

【问题讨论】:

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


    【解决方案1】:

    如果您不需要比较当前的 this.props 和 nextProps,最好在其他地方触发导航操作。

    此链接也可能对您有所帮助:https://facebook.github.io/react/docs/react-component.html#the-component-lifecycle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-10
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 2021-01-31
      • 2020-04-14
      • 2017-04-19
      相关资源
      最近更新 更多