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

How to type navigation in react-navigation library?

$
0
0

I am using react-navigation 5.5.1, all is working great but I have some trouble with typescript.

I tried to type the navigation prop according to the docs (https://reactnavigation.org/docs/typescript/) but it looks like navigation is still type any.

Any clues what I missed?

export type AppParamList = {  Intro: undefined;  Stories: undefined;};interface RoutesProps {}const Stack = createStackNavigator<AppParamList>();const Routes: FC<RoutesProps> = () => {  return (<SafeAreaProvider><NavigationContainer><Stack.Navigator><Stack.Screen name="Intro" component={Intro} /><Stack.Screen name="Stories" component={Stories} /></Stack.Navigator></NavigationContainer></SafeAreaProvider>  );};// Intro.tsximport { StackNavigationProp } from '@react-navigation/stack';import { AppParamList } from ../type IntroScreenNavigationProp = StackNavigationProp<AppParamList, 'Intro'>;type Props = {  navigation: IntroScreenNavigationProp;};const Intro = ({ navigation }: Props): ReactElement => (<SafeAreaView><Text>Intro</Text><TouchableHighlight onPress={() => navigation.navigate('Stories')}><Text>Go to stories</Text></TouchableHighlight></SafeAreaView>);

enter image description here


Viewing all articles
Browse latest Browse all 6213

Trending Articles



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