Skip to content

Instantly share code, notes, and snippets.

@josephajibodu
Created July 8, 2022 11:54
Show Gist options
  • Save josephajibodu/5b2b8cb2c911945347b362d1e0a2f818 to your computer and use it in GitHub Desktop.
Save josephajibodu/5b2b8cb2c911945347b362d1e0a2f818 to your computer and use it in GitHub Desktop.
React Navigation v6 with Typescript
import { createNativeStackNavigator, NativeStackScreenProps } from '@react-navigation/native-stack';
import { Button, View } from 'react-native';
export type RootStackParamList = {
Home: undefined;
Profile: undefined;
Settings: {
userId: number;
};
};
const Stack = createNativeStackNavigator<RootStackParamList>();
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={() => <View />} />
<Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen name="Settings" component={() => <View />} />
</Stack.Navigator>
type ProfileProps = NativeStackScreenProps<RootStackParamList, 'Profile'>;
// Every react-navigation screen receives route and navigation props
function ProfileScreen({ route, navigation }: ProfileProps) {
return (<View>
<Button
title='Go to Settings'
onPress={() => {
navigation.navigate('Settings', {
userId: 4
});
}}
/>
</View>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment