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

Setting parent screen options based on child navigator's state inTypescript

$
0
0

How can I set parent screen options based on child navigator's state in react navigation version 5 using Typescript. Actually it is described in documentation. But types are not mentioned for routes. Here is the working code described in documentation:

function getHeaderTitle(route) {// Access the tab navigator's state using `route.state`const routeName = route.state? // Get the currently active route name in the tab navigator  route.state.routes[route.state.index].name: // If state doesn't exist, we need to default to `screen` param if available, or the initial screen  // In our case, it's "Feed" as that's the first screen inside the navigator  route.params?.screen || 'Feed'; switch (routeName) {  case 'Feed':  return 'News feed';  case 'Profile':  return 'My profile';  case 'Account':  return 'My account';  } }<Stack.Screen  name="Home"  component={HomeTabs}  options={({ route }) => ({  headerTitle: getHeaderTitle(route),  })} />

How can I implement this in typescript and is there any guide for version 5 in typescript?


Viewing all articles
Browse latest Browse all 6212

Trending Articles



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