首页 > 其他分享 >React报错之Element type is invalid

React报错之Element type is invalid

时间:2022-12-18 14:22:14浏览次数:51  
标签:function React Header 导入 报错 router 组件 export type

总览

产生"Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got"错误有多个原因:

  1. 在导入组件时,将默认导入和命名导入混淆。
  2. 忘记从文件中导出组件。
  3. 不正确地定义了一个React组件,例如,作为一个变量而不是一个函数或类。

type-is-invalid-expected-string-but-got.png

为了解决该错误,确保使用大括号来导入命名导出而不是默认导出,并且只使用函数或类作为组件。

这里有个示例来展示错误是如何发生的。

// 

标签:function,React,Header,导入,报错,router,组件,export,type
From: https://www.cnblogs.com/chuckQu/p/16990350.html

相关文章