当我在反应导航的功能组件中使用goBack(null(方法时,我遇到了一些错误
function Header({ titleText, navigation}) {
return (
<Appbar.Header style={styles.headerContainer}>
<Appbar.BackAction style={styles.backButton} onPress={() => navigation.goBack(null)} >
<Text style={styles.back}></Text>
</Appbar.BackAction>
<View style={styles.container}>
<Title style={styles.title}>{titleText}</Title>
</View>
</Appbar.Header>
)}
从@react-navigation/native
尝试使用useNavigation
挂钩
import * as React from 'react';
import { Text } from 'react-native';
import { useNavigation } from '@react-navigation/native';
function MyText() {
const navigation = useNavigation();
return <Text onPress={() => navigation.goBack()}>Go Back</Text>;
}