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

React Navigation route.params typescript

$
0
0

I'm creating a Expo managed React Native app with TypeScript and having some problems with React Navigation and TypeScript.

I want to specify the icon for the Bottom Tab Navigator on the Tab.Screen component.

This code works but complains because route.params could be undefined (line 10).

Property 'icon' does not exist on type 'object'

Can I make the icon prop required on initialParams?

I have looked in the documentation without any luck.

const App: React.FC<{}> = () => {  return (<SafeAreaView style={styles.container}><NavigationContainer><Tab.Navigator          screenOptions={({ route }) => ({            tabBarIcon: ({ size, color }) => (<MaterialIcons                size={size}/* ===> */      name={route.params.icon}                color={color}              />            ),          })}><Tab.Screen            name="EventListView"            initialParams={{ icon: 'view-agenda' }}            component={EventListScreen}          /><Tab.Screen            name="CreateEvent"            initialParams={{ icon: 'public' }}            component={SettingsScreen}          /></Tab.Navigator></NavigationContainer></SafeAreaView>  )}

Viewing all articles
Browse latest Browse all 6213

Trending Articles



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