我使用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] 删除。
我来说两句