问题描述
在我的本机应用程序中,我正在使用本机路由器流量,同时返回上一屏幕时,我希望上一屏幕重新呈现或刷新。我正在使用Action.pop()返回上一个。如何刷新上一个屏幕?
解决方法
您需要在屏幕上的导航对象上侦听“焦点”事件,并在事件处理程序中添加用于获取新数据的逻辑。
function YourScreenComponent({ navigation }) {
React.useEffect(() => {
const unsubscribe = navigation.addListener('focus',() => {
// fetch new data here
});
return unsubscribe;
},[navigation]);
return <SomeContent />;
}
,
我使用反应路由器流量的Action.reset(“屏幕的键”)解决了该问题