We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
navigate
I got type error while I write my custom navigateTo function.
navigateTo
function HomeScreen() { const navigation = useNavigation<StackNavigationProp<RootStackParamList>>(); function navigateTo( screen: keyof RootStackParamList, params?: RootStackParamList[keyof RootStackParamList], ) { navigation.navigate(screen, params); } return ( <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}> <Text>Home Screen</Text> </View> ); }
import React from 'react'; import {Text, View} from 'react-native'; import { createStackNavigator, StackNavigationProp, } from '@react-navigation/stack'; import { NavigationContainer, RouteProp, useNavigation, useRoute, } from '@react-navigation/native'; function HomeScreen() { const navigation = useNavigation<StackNavigationProp<RootStackParamList>>(); function navigateTo( screen: keyof RootStackParamList, params?: RootStackParamList[keyof RootStackParamList], ) { navigation.navigate(screen, params); } return ( <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}> <Text>Home Screen</Text> </View> ); } function DetailsScreen() { const route = useRoute<RouteProp<RootStackParamList, 'Details'>>(); return ( <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}> <Text>Details Screen {route?.params?.userId}</Text> </View> ); } type RootStackParamList = { Home: undefined; Details: {userId: string}; }; const Stack = createStackNavigator<RootStackParamList>(); const App = () => { return ( <NavigationContainer> <Stack.Navigator> <Stack.Screen name="Home" component={HomeScreen} /> <Stack.Screen name="Details" component={DetailsScreen} /> </Stack.Navigator> </NavigationContainer> ); }; export default App;
Should not have type error because with v5 the type is correct.
https://github.com/thormengkheang/TestRN
The text was updated successfully, but these errors were encountered:
Couldn't find version numbers for the following packages in the issue:
react-native-tab-view
flipper-plugin-react-navigation
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.
Sorry, something went wrong.
Also have the same issue. When I provide a screenName through a function param, I get the same behaviour
No branches or pull requests
Current behavior
I got type error while I write my custom
navigateTo
function.Expected behavior
Should not have type error because with v5 the type is correct.
Reproduction
https://github.com/thormengkheang/TestRN
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: