reactjs - React 16.2 <Fragment> 给出未捕获错误 : Element type is invalid

标签 reactjs typescript

我刚刚更新到 React 16.2,我想使用很酷的 Fragment 功能。但是,只要以简单的方式使用它,我就会遇到奇怪的错误:

<React.Fragment>asd</React.Fragment>

错误状态:未捕获错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:符号。

当我记录上面的代码和我定义的随机组件时,我得到以下信息:

$$typeof: Symbol(react.element)
key: null
props: {children: "asd"}
ref: null
type: Symbol(react.fragment)
...

当我记录我的元素时,我得到几乎相同的信息:

$$typeof: Symbol(react.element)
key: null
props: {children: "sfdghs"}
ref: null
type:ƒ Column(_ref)

我的问题是:为什么应用需要字符串或函数。

我的 package.json 中的所有相关依赖项都是这样的:

  • "devDependencies": {... "@types/react": "^16.0.0"...}
  • "dependencies": {... "react": "^16.2.0", "typescript": "2.6.2"...}

如果有人能给我任何关于如何调试它的信息,我将不胜感激!

最佳答案

reactreact-dom 都需要最低 16.2.0

关于reactjs - React 16.2 <Fragment> 给出未捕获错误 : Element type is invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47714780/

相关文章:

javascript - 当我调用数组中对象的属性时出现错误

angular - RxJS observable 在 mergeMap 后不触发订阅

reactjs - 类型 'amp-img' 上不存在属性 'JSX.IntrinsicElements'

javascript - 可以访问event.target,它有value属性,但是event.target.value总是返回undefined?

reactjs - 即使启用计费帐户后,我在使用 google map place api 时仍然收到 "Status: OVER_QUERY_LIMIT"

javascript - ReactJS 问题 : () => vs function ()

typescript - 如何让 TypeScript 加载 cordova 插件中包含的类型

具有多个字符串值的 typescript 枚举

javascript - 语义 UI 中的格式化工具提示

javascript - React/Jest/Enzyme 浅渲染测试中如何将文本输入到表单中?