【发布时间】:2021-06-06 02:48:11
【问题描述】:
这个问题是针对 React Native 应用程序中的 React Navigation 5 的。将道具传回父屏幕时,如何在父屏幕中为useEffect 设置触发器?这是一个例子:
Child Screen
_onPress = (country, country_code, calling_code) => {
const { navigation, route } = this.props;
navigation.navigate("parent"
{select:{
country_name: country,
country_code: country_code,
calling_code: calling_code
});
};
在父组件上。 useEffect 用于在子屏传回 props select 后做一些事情:
useEffect(()=> {
if (route.params?.select?) {
//do something after select is passed back
}
}, [what is the trigger?]) //<<==how to setup trigger for useEffect?. [] did not work.
如何在父组件中为 useEffect 设置触发器?尝试使用 [] 将触发任何重新加载,但它没有工作。相同的 props select 是否应该从父组件传递到子屏幕并在子屏幕更新后再次传递回父组件? select 是触发器吗?
【问题讨论】:
标签: react-navigation react-navigation-v5