【问题标题】:What the different between React$Element and ReactElementReact$Element 和 ReactElement 有什么不同
【发布时间】:2017-11-06 12:55:25
【问题描述】:

我正在尝试将流与 ReactJS 一起使用。我需要为道具儿童添加类型。文章 (Flow + React) 并没有说明任何内容。

我发现了很多使用 ReactElement (e.g) 的示例。但是流说identifier ReactElement. Could not resolve name。我使用 React$Element 并且它有效。

问题。 React$Element 和 ReactElement 有什么区别?我在哪里可以找到有关 React$Element 的信息?流搜索类型定义在哪里。

【问题讨论】:

    标签: javascript reactjs flowtype flow-typed


    【解决方案1】:

    React$Element 当前位于与Flow 捆绑的“react.js”库文件中:

    /**
     * Type of a React element. React elements are commonly created using JSX
     * literals, which desugar to React.createElement calls (see below). The type
     * parameterization of React$Element mimics that of ReactClass (see above).
     */
    declare class React$Element<Config> {
      type: ReactClass<Config>;
      props: $PropsOf<Config>;
      key: ?string;
      ref: any;
    }
    

    正如 Flow 团队在其 Introducing Flow Typed 博客文章中提到的那样,它最终可能会转移到新的 flowtype/flow-typed repo。如果您需要从 NPM 安装的库的定义,可以查看“流类型”。

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 2018-12-31
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      • 2021-01-12
      • 1970-01-01
      • 2022-12-13
      相关资源
      最近更新 更多