GoBack react native üzerinde ekranı yeniden yükle
Aug 26 2020
Bir yığın gezgininde iki ekran olduğunu varsayalım:
First_Screen -> Second_Screen
This.props.navigation.goBack () 'i çağırarak önceki ekrana dönerken nasıl yenileyebilir / yeniden yükleyebiliriz?
Aşağıdaki react-native ve react-navigasyon sürümlerini kullanıyorum:
"react-native": "0.63.2",
"@react-navigation/native": "^5.7.3",
"@react-navigation/stack": "^5.9.0",
Aşağıdakileri denedim
componentDidMount() {
this.props.fetchData();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
this.props.fetchData();
}
);
}
componentWillUnmount() {
this.willFocusSubscription.remove();
}
Ancak beklenen sonucu alamadı.
Yanıtlar
1 rishikesh_07 Aug 27 2020 at 01:25
bunu dene, işe yarayacak
componentDidMount() {
this.onFocusCall = this.props.navigation.addListener('willFocus', () => {
this.apiCall();
});
}
componentWillUnmount() {
this.onFocusCall.remove();
}
1 SaachiTech Aug 27 2020 at 06:04
React-navigation 5x kullandığınız için dinleyiciyi aşağıdaki şekilde güncellemeniz gerekir
componentDidMount() {
this.props.fetchData();
this.willFocusSubscription = this.props.navigation.addListener(
'focus',
() => {
this.props.fetchData();
}
);
}
dokümanlar: https://reactnavigation.org/docs/function-after-focusing-screen/
1 ParthNavadiya Oct 28 2020 at 06:21
Bunu dene, iyi çalışıyor
useEffect(() => {
const unsubscribe = navigation.addListener("focus", async () => {
const response = await apiCall();
});
return unsubscribe;
}, [navigation]);
Donovan, Şarkılarından 1'ini The Beatles'ın "Lucy in the Sky with Diamonds" şarkısıyla karşılaştırdı
Gene Simmons, KISS Çizgi Romanlarının Potansiyel Olarak "İnsanlığı Yeniden Yaratabileceğini" Söyledi
Charly Reynolds Yakın Zamandaki Vokal Kord Ameliyatını Açıkladı: 'Şarkı Söylemekte Sorun Yaşıyordum'