下面的如何传递道具和导航来响应本机代码

时间:2020-05-07 23:22:21

标签: typescript react-native

我正在使用打字稿进行本机反应。

如何在界面中通过Navigation,下面的代码片段是Functional组件或class组件。 Reach.FC表示什么?

interface HomeScreenProps {}

export const HomeScreen: React.FC<HomeScreenProps> = ({}) => (
  <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
    <Text>Home!</Text>
  </View>
)

1 个答案:

答案 0 :(得分:0)

您可以使用@react-navigation/native@react-navigation/stack提供的类型;

import { RouteProp } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';

type RootParams = {
  Home: undefined;
};

type HomeScreenRouteProps = RouteProp<RootParams, 'Home'>;

type HomeScreenNavigationProps = StackNavigationProp<
  RootParams,
  'Home'
>;

interface HomeScreenProps = {
  route: HomeScreenRouteProps;
  navigation: HomeScreenNavigationProps;
};

export const HomeScreen: React.FC<HomeScreenProps> = ({ navigate, route }) => (
  <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
    <Text>Home!</Text>
  </View>
)