Property 'pop' does not exist on type 'NavigationProp<Record<string, object | undefined>, string, NavigationState, {}, {}>'

Viewed 346

How can we use the pop() function in React Native Navigation?

onPress={() => navigation.pop('Home')}>

gives me a TypeScript error that

Property 'pop' does not exist on type 'NavigationProp<Record<string, object | undefined>, string, NavigationState, {}, {}>'.ts(2339

2 Answers
const navigation = useNavigation<StackNavigationProp<any>>();

if the above snippet didn't help try

const navigation = useNavigation<any>();

if you are using import { NavigationContext } from '@react-navigation/native';

const navigation = React.useContext<any>(NavigationContext);

You have to annotate the navigation prop that we get from useNavigation

types.ts:

export type RootStackParamList = {
  Home: undefined;
}

your file:

const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();
Related