gpt4 book ai didi

javascript - React$Element 和 ReactElement 有什么区别

转载 作者:行者123 更新时间:2023-11-29 15:20:25 30 4
gpt4 key购买 nike

我正在尝试将 Flow 与 ReactJS 结合使用。我需要为 prop children 添加类型。文章 ( Flow + React) 对此没有任何说明。

我发现了很多使用 ReactElement ( e.g ) 的示例。但是流程说 identifier ReactElement。无法解析名称。我使用 React$Element<*> 并且它有效。

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

最佳答案

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;
}

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

关于javascript - React$Element 和 ReactElement 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44374219/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com