gpt4 book ai didi

reactjs - 或 <> 上出现流错误,但 上没有流错误

转载 作者:行者123 更新时间:2023-12-03 13:33:07 25 4
gpt4 key购买 nike

我正在使用react v16.3.0flow-bin v0.69.0

使用 react Fragments<React.Fragment>或简写<></>语法如下

import React from 'react'

const ComponentA = () => (
<React.Fragment>
<div>Component</div>
<div>A</div>
</React.Fragment>
)

const ComponentB = () => (
<>
<div>Component</div>
<div>B</div>
</>
)

Flow 提示以下错误(这两个错误都是相同的错误,仅在此处显示 ComponentA 的输出)

Cannot get React.Fragment because property Fragment is missing in object type [1].

24│ const ComponentA = () => (
25│ <React.Fragment>
26│ <div>Component</div>
27│ <div>A</div>
28│ </React.Fragment>

/private/tmp/flow/flowlib_2349df3a/react.js
251│ declare export default {|
252│ +DOM: typeof DOM,
253│ +PropTypes: typeof PropTypes,
254│ +version: typeof version,
255│ +initializeTouchEvents: typeof initializeTouchEvents,
256│ +checkPropTypes: typeof checkPropTypes,
257│ +createClass: typeof createClass,
258│ +createElement: typeof createElement,
259│ +cloneElement: typeof cloneElement,
260│ +createFactory: typeof createFactory,
261│ +isValidElement: typeof isValidElement,
262│ +Component: typeof Component,
263│ +PureComponent: typeof PureComponent,
264│ +Children: typeof Children,
265│ |};

显式导入 Fragment然而,Flow 并没有提示。

import { Fragment, default as React } from 'react'

const ComponentC = () => (
<Fragment>
<div>Component</div>
<div>C</div>
</Fragment>
)

这是怎么回事?我想使用<></>片段速记语法,这个问题目前阻止我这样做。

当我深入研究react.js时错误中引用的 lib def 似乎该错误实际上是正确的 - Fragment 的导出已定义,而片段定义为默认导出上的属性。

但是流程文档 state that flow has support for react Fragmentsv0.59开始。

那么这实际上仍然存在支持差距吗?或者我做错了什么?也许我有一个过时的 lib def 或者配置错误?我无法通过谷歌搜索找到任何错误消息,这让我怀疑这是我的设置问题。而且我不太相信这行不通。

最佳答案

此提交中包含在定义中包含 React.Fragment 的修复: https://github.com/facebook/flow/commit/b76ad725177284681d483247e89739c292ed982b

它应该在流程0.71中可用

关于reactjs - <React.Fragment> 或 <></> 上出现流错误,但 <Fragment> 上没有流错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49320552/

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