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

How to make navigator screen component receive props passed to it

$
0
0

I have a stack navigator with a screen component:

const Stack = createStackNavigator<StackParamList>(); // StackParamList is custom typefunction Navigator() {  return (<Stack.Navigator initialRouteName="comp"><Stack.Screen name="comp" component={Component} /></Stack.Navigator>  );}

By default react-navigation pass props route and navigation to the screen component and to use these, the component must be defined like below as mentioned in official documentation:

export default function Component({route, navigation}){  // User `route` and `navigation` however you like it}

My IDE also prompts me to provide types for props something like:

export default function Component({route: RouteType, navigation: NavigationType})

Easiest way to do this is to specify RouteType and NavigationType as any but I would rather avoid it to get most out of static type checking. So, what is the best way to receive these route and navigation props? What exactly should be in RouteType and NavigationType excluding any?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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