【问题标题】:Which type props have in functional components of react?react 的功能组件中有哪些类型的 props?
【发布时间】:2021-03-26 11:22:10
【问题描述】:

我需要将 react 组件 props 传递给另一个组件,例如:

interface IMyComponent {
    props: Props<any>
}

const MyComponent: FC = ({ props }) => {
}

如您所见,我在阅读此问题后尝试使用 React.Props 类型: Interface props in functional components

但现在是 2021 年,我使用 “反应”:“^17.0.1”和“打字稿”:“^4.1.3” 我收到一条消息说 React.Props 已被弃用。

我应该使用哪种类型的道具?

另外,如果我能获得一本手册的链接,我会很感激,我可以在其中找到 React 中任何东西的类型,因为现在检测某些 React 事物的类型非常困难,而且 React 文档在 Typescript 中没有示例。那是一种痛苦。

【问题讨论】:

  • 因为现在检测一些 React 事物的类型非常困难,而且 React 文档在 Typescript 中没有示例。这很痛苦。 - 只需检查输入源文件。在 TS 中总是这样。

标签: reactjs typescript types react-props


【解决方案1】:

我通常这样做like in this code snippet。基本上是创建您自己的类型,并在 React.FC 中传递并在其中定义每个属性的类型。

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2021-10-21
    • 2016-09-23
    • 2020-10-09
    • 2023-03-27
    • 2020-05-07
    • 2020-09-19
    • 1970-01-01
    相关资源
    最近更新 更多