React Native 与 ReactJS 中的 componentWillReceiveProps

componentWillReceiveProps in React Native vs ReactJS

我正在将我的 React Webapp 转移到 React Native 版本。

在 React Native 中,我在登录页面中有这个。我正在使用反应导航。

componentWillReceiveProps(nextProps) {
    const { requestStatus, currentUser } = nextProps
    const getUserInProgress = get(requestStatus, GET_MY_DETAILS, true)

    if (!getUserInProgress) {
      if (currentUser) {
        currentUser.verified_mobile ? this.props.navigation.navigate('Dashboard') : this.props.navigation.navigate('VerifyMobile')
      } else if (!currentUser) {
        console.log('not logged in')
      }
    }
  }

因此在登录页面上,它获取用户详细信息并检查手机是否已验证,如果未验证,则转到验证手机页面。

在验证移动页面上,当调用时,登录页面上的此 componentWillReceiveProps 仍然 运行s,即使它不是当前活动页面。

我在 ReactJS 中有相同的 logic/code,但它的行为完全不同。

这对 React Native 来说正常吗?

编辑:

让我澄清一下我的问题是什么。

当我不在登录页面上时,我在验证手机页面上。尽管该页面在历史记录中,但 componentWillReceiveProps 仍然 运行ning。当我构建 reactjs 应用程序时,这并没有发生。它只发生在反应本机应用程序中。所以我想知道这是否是历史堆栈中页面到 运行 其 componentWillReceiveProps 的正常行为?

该函数在react-native中仍然执行,因为它仍然在堆栈中处于活动状态,而在rea​​ct app中,只有显示的页面处于活动状态,因此其他页面中的函数在某种意义上是'disabled'。