简体   繁体   English

typescript 中的路线(反应导航)类型

[英]route (react-navigation) type in typescript

For navigations, I am using useNavigation from '@react-navigation/native';对于导航,我使用useNavigation from '@react-navigation/native';

I am using this to pass data between two screens in my app:我正在使用它在我的应用程序的两个屏幕之间传递数据:

type UserDetailsProps = {
  onDeleteContact: (id: number) => void;
  route: any;
};

I don't want to use the any time but I don't know what other type is suitable here.我不想在any时候使用,但我不知道这里适合什么其他类型。

You can use this type:您可以使用这种类型:

type RouteParams = {
  firstName?: string;
}

route?: RouteProp<Record<string, RouteParams>, ''>;

Notice that RouteProp is a named export of @react-navigation/native请注意,RouteProp 是@react-navigation/native的命名导出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM