首页 > 解决方案 > 如何在 React 导航 5x 中定义导航属性类型

问题描述

我正在做新项目。我开始在这个项目中使用打字稿。当我开始新项目时,我使用了 React Navigation 5x 版本。我的问题,如何在反应导航 5x 版本中定义界面破坏导航道具类型?我不使用任何类型。我阅读了文档反应导航,但我没有找到我的问题。非常感谢。希望你有个美好的一天。

import React from 'react';
import {Button, Text, SafeAreaView} from 'react-native';
import {inject, observer} from 'mobx-react';
import {Col, Grid} from 'react-native-easy-grid';
import Stores from '../../stores/storeIdentifier';
import ThemeStore from '../../stores/themeStore';

interface Props {
  navigation: any;
}
interface InjectedProps extends Props {
  themeStore: ThemeStore;
}

export function ModalComponent(props: Props) {
  const {themeStore, navigation} = props as InjectedProps;
  return (
    <SafeAreaView style={themeStore.styleSheet.globalModal__container}>
      <Grid>
        <Col
          style={[
            themeStore.styleSheet.alignCenter,
            themeStore.styleSheet.justifyCenter,
          ]}>
          <Text>Welcome to Global Modal </Text>
          <Button onPress={() => navigation.goBack()} title="Back" />
        </Col>
      </Grid>
    </SafeAreaView>
  );
}
export const Modal = inject(Stores.ThemeStore)(observer(ModalComponent));

标签: typescriptreact-nativereact-navigation

解决方案


推荐阅读