Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to specify the type for the return of useNavigation

$
0
0

I'm having some diffuculties specifing the parameters for a function (onError) that receive the return of a useNavigation())

import { useNavigation } from '@react-navigation/native'import { NativeStackNavigationProp } from '@react-navigation/native-stack'import { RootStackParamList } from '~/navigation/types'export function useErrorHandling() {  const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>()  // const navigation = useNavigation() // this does not have the .replace but can't pass it to onError without type issue.  return { onError: (error: unknown) => onError(navigation, error) }}export function onError(  nav: ReturnType<typeof useNavigation<NativeStackNavigationProp<RootStackParamList>>>,  error: unknown) {  // nav.replace // does not throw type error  nav.navigate('Error', { error: error instanceof Error ? error.message : 'Unknow error' })}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>