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

How should I define type of props supplied by react-navigation?

$
0
0

I have a react native app with navigation stack defined:

<Stack.Navigator            initialRouteName={NavigationLocations.SIGNUP}            ...            }}>           ...<Stack.Screen                name={NavigationLocations.SHEET}                component={Sheet}                options={                    {                        title: "Character sheet",                        headerLeft: null                    }}            /></Stack.Navigator>

This is my navigation props definition:

export type RootStackParamList = {    Signup: undefined,    Login: undefined,    Dashboard: undefined,    SheetView: {sheet: ISheet}};

How should I define the sheet props in the component that is receiving the sheet object passed by the navigation?

type Props = StackScreenProps<RootStackParamList, NavigationLocations.SHEET>export default function Sheet({sheet}: Props) {    const sheet = props.route.params.sheet;

Currently I am getting this error: Error:(11, 32) TS2339: Property 'sheet' does not exist on type 'StackScreenProps<RootStackParamList, NavigationLocations.SHEET>'.

I am using the NavigationLocations enum because I generally dislike using strings as identifiers, but I think that my implementation has introduced an error here. What am I doing wrong?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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