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' })}