在react-native-router-flux中使用Actions.reset(“ key”)时,会影响组件的因素

雷诺阿罗德

我使用react-native-router-flux作为react-native路由器,在我的情况下,当用户注销时,我使用Action.reset(“ key”),但getDerivedStateFromProps next props仍然有前置数据,任何人都可以告诉我原因,或如何使用其他方式解决问题。

詹姆士

react-native-router-flux基于react-navigaion。所以我们可以找到概念和解释。

首先我们看到源js代码,它位于navigationStore中

reset = (routeName, data) => {
    const params = filterParam(data);
    const parent = getParent(this.state, routeName);
    this.dispatch(
      StackActions.reset({
        index: 0,
        key: parent ? parent.key : null,
        actions: [
          NavigationActions.navigate({
            routeName,
            params,
          }),
        ],
      }),
    );
  };
}

StackActions.reset只复位动作擦拭整个导航状态,并与几个动作的结果替换它。因此它只会更改导航状态。我们可以在react-navigation api中看到这一点

对于导航生命周期,与Web不同,导航不会重新安装组件。它管理路由器使用堆栈。以下是官方的说法:

Consider a stack navigator with screens A and B. After navigating to A, its componentDidMount is called. When pushing B, its componentDidMount is also called, but A remains mounted on the stack and its componentWillUnmount is therefore not called.

When going back from B to A, componentWillUnmount of B is called, but componentDidMount of A is not because A remained mounted the whole time.

因此,将组件从路由器堆栈中移除时,导航将卸载该组件,例如返回,重置

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

react-native-router-flux Actions.{key} 无法识别并在调用时导致错误

react-native-router-flux,重载时保持状态

如何设置react-native-router-flux?

使用React Native Router Flux的延迟加载屏幕

使用react-native-router-flux自定义navBar

使用React Native Router Flux / Redux保护路由(场景)

如何将react-native-router-flux与react-native-drawer结合使用

如何将道具传递到Actions.replace react-native-router-flux

react-native:如何结合 react-native-router-flux 和 react-native-drawer?

如何将值传递给React-Native-Router-Flux中的其他组件?

如何在react-native-router-flux中设置Scene组件的标题

当我在App组件上使用setState()时,将Context API与react-native-router-flux结合使用可重置堆栈

在React中使用react-router时组件消失

使用React-Router-Native从React Native中的Axios拦截器(组件外部)重定向到View组件

未找到 React Native 模塊:無法使用 react-native-router-flux 解析“@react-navigation/core”

React Native Router Flux:从主场景导航到子场景

在 react-native-router-flux 上从堆栈中弹出导航

在 React Native Router Flux 中跨主要场景导航

react-native-router-flux将道具传递给场景

如何配置 react-native-router-flux android back history?

React-native-router-flux动态更新rightButtonImage

在 react-native-flux-router 中传递道具

React-Native-Router-flux防止多次点击

为什么我的 setTimeout 功能在我使用 react-native 和 react-router-native 时不起作用

React Native Router Flux:使用相同场景但使用其他参数的转换和历史

使用react-native-router-flux将数据从屏幕发送到Tab屏幕

使用React Native Router Flux将道具传递到TabIcon中

使用 react-native-router-flux 无法正确显示导航栏和选项卡

如何使用 react-native-router-flux 设置作为选项卡子项的场景的标题