发布于 2021-02-19 11:18:06
你可以这样做:
/**
* Your redux action should set loading-state to false after
* fetch-operation is done...
*/
reduxActionDoingFetch();
useEffect(() => {
if (reduxActionDoingFetch_Loading === false) {
Navigation.navigate('YourTargetScreen');
}
}, [reduxActionDoingFetch_Loading]);发布于 2021-02-22 02:13:01
不能在componentDidMount之前获取数据。这是在呈现新屏幕时发生的第一件事。
对于每次屏幕聚焦时获取数据,您需要使用迁移指南中提到的focus事件:https://reactnavigation.org/docs/upgrading-from-4.x/#navigation-events。
与以前的focus事件等效的willFocus事件。在动画完成之前,只要屏幕聚焦,它就会启动。我不知道你说的太晚了是什么意思。
另外,对于数据获取,有一个特殊的钩子:useFocusEffect
发布于 2021-02-19 11:22:08
React.useEffect(() => {
const unsubscribe = navigation.addListener('focus', () => {
// do something
});
return unsubscribe;
}, [navigation]);https://stackoverflow.com/questions/66276165
复制相似问题