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

React Navigation annotating useNavigator with BottomTabs

$
0
0

Can anybody help with typing / annotating useNavigator with RootStack -> Tabs -> Each tab has a stack setup.

import { useNavigation } from '@react-navigation/native';import { NativeStackNavigationProp } from '@react-navigation/native-stack';import type {  CompositeScreenProps,  NavigatorScreenParams,} from '@react-navigation/native';import type { NativeStackScreenProps } from '@react-navigation/native-stack';import type { BottomTabScreenProps } from '@react-navigation/bottom-tabs';export type RootStackParamList = {  Home: NavigatorScreenParams<HomeTabParamList>;};export type RootStackScreenProps<T extends keyof RootStackParamList> =  NativeStackScreenProps<RootStackParamList, T>;export type HomeTabParamList = {  Dashboard: undefined;  Map: undefined;};export type HomeTabScreenProps<T extends keyof HomeTabParamList> =  CompositeScreenProps<    BottomTabScreenProps<HomeTabParamList, T>,    RootStackScreenProps<keyof RootStackParamList>>;declare global {  namespace ReactNavigation {    interface RootParamList extends RootStackParamList {}  }}export default () =>  useNavigation<NativeStackNavigationProp<RootStackParamList>>();
const navigation = useNavigator()navigation.navigate('Dashboard') // Throws type error, only 'Home' is a suggestion.

Viewing all articles
Browse latest Browse all 6287

Trending Articles