我正在开发 React Native Expo App 并使用 Hooks 开发 React 导航版本 5。如何更新 goBack() 上的状态?
const fetchData = async (props) => {
//http request
}
useEffect(() => {
fetchData(props);
}, [props]);
return(
<View>
<TouchableOpacity onPress={() => props.navigation.navigate('Settings',{onGoBack, () => fetchData(props)})}>
</TouchableOpacity
</View>
)
const submit = () => {
props.navigation.route.params.onGoBack();
props.navigation.goBack();
}
在导航状态中发现不可序列化的值,这可能会破坏持久和恢复状态等使用。如果您在参数中传递不可序列化的值(例如函数、类实例等),则可能会发生这种情况。如果您需要在选项中使用带有回调的组件,则可以使用“navigation.setOptions”。有关更多详细信息,请参阅 https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serialized-values-were-found-in-the-navigation-state。