React native 在react native router flux中使用Actions.reset(“key”)时,什么会影响组件
我使用react native router flux作为react native router,在我的情况下,当用户注销时,我使用Action.reset(“键”),但是React native 在react native router flux中使用Actions.reset(“key”)时,什么会影响组件,react-native,router,react-native-router-flux,React Native,Router,React Native Router Flux,我使用react native router flux作为react native router,在我的情况下,当用户注销时,我使用Action.reset(“键”),但是getDerivedStateFromPropsnext props仍然有预数据,有人能告诉我原因吗,或者如何使用另一种方法解决问题。react本机路由器流量基于react navigaion。因此,我们可以找到概念和解释 首先我们看到源js代码,它位于navigationStore中 reset = (routeName,
getDerivedStateFromProps
next props
仍然有预数据,有人能告诉我原因吗,或者如何使用另一种方法解决问题。react本机路由器流量基于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导航中看到这一点
对于导航生命周期,与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.
因此,当组件从路由器堆栈中移除时,导航将卸载该组件,如back,resetI debug my app,重置时,重新创建并装载该组件