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

how to use two different route name with params for the same used component on react native in navigation

$
0
0

let's suppose I have the typing like the following

export type NavProp<  ParamList extends ParamListBase,  RouteName extends keyof ParamList = string> = {  nav: NativeStackNavigationProp<ParamList, RouteName>;  route: RouteProp<ParamList, RouteName>;};

and one component

type NavPrams = {'my_screen': { title: string;};};type Props = NavProp<NavPrams, 'my_screen'>export default function MyComponent (props: Props) {return <Text>hello {props.title}</Text>}

and in Navigation I have for example :

...<NavigationContainer><Stack.Navigator><Stack.Screen name='my_screen' component={MyComponent}/><Stack.Screen name='my_screen2' component={MyComponent}/> // issue is here different name of screen</Stack.Navigator></NavigationContainer>...

the issue will show us a message like

....Types of parameters 'props' and 'props' are incompatible.      Type '{}' is missing the following properties from type 'Omit<ClassAttributes<MyComponent> ...

Note: I don't want to create duplicated things like comp , props...I want something generated


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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