简体   繁体   English

头盔不是有效的 jsx 元素

[英]Helmet is not a valid jsx element

i have this problem in the react boilerplate template.我在反应样板模板中有这个问题。

typsecript error打字错误
'Helmet' cannot be used as a JSX component. “头盔”不能用作 JSX 组件。 Its instance type 'Helmet' is not a valid JSX element.它的实例类型“头盔”不是有效的 JSX 元素。 TS2786 TS2786

     7 |   return (
     8 |     <>
  >  9 |       <Helmet>
       |        ^
    10 |         <title>404 Page Not Found</title>
    11 |         <meta name="description" content="Page not found" />
    12 |       </Helmet>

imported as导入为

import { Helmet } from 'react-helmet-async';

investigating the "" shows this error调查“”显示此错误

HelmetProvider' cannot be used as a JSX component. HelmetProvider' 不能用作 JSX 组件。 Its instance type 'HelmetProvider' is not a valid JSX element.它的实例类型“HelmetProvider”不是有效的 JSX 元素。 Type 'HelmetProvider' is missing the following properties from type 'ElementClass': render, context, setState, forceUpdate, and 3 more.ts(2 “HelmetProvider”类型缺少“ElementClass”类型的以下属性:render、context、setState、forceUpdate 和 3 个更多。ts(2

`import { HelmetProvider } from 'react-helmet-async';

why is this not working?为什么这不起作用?

I was able to resolve this by installing @types/react-helmet.我可以通过安装 @types/react-helmet 来解决这个问题。

npm install --save @types/react-helmet

https://github.com/staylor/react-helmet-async#usage https://github.com/staylor/react-helmet-async#usage

I think you need to default import it, as you might be using the older version.我认为您需要默认导入它,因为您可能使用的是旧版本。

import Helmet from 'react-helmet-async'

I used react 17. So I resolved it by adding this to package.json:我使用了 react 17。所以我通过将其添加到 package.json 来解决它:

"resolutions": {
   "@types/react": "17.0.2",
   "@types/react-dom": "17.0.2"
},

I also hit this error using the react boilerplate template.我也使用反应样板模板遇到了这个错误。 This resolved the error for me!这为我解决了错误!

yarn upgrade @types/react@latest

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “HelmetProvider”不是有效的 JSX 元素 - 'HelmetProvider' is not a valid JSX element “ReactNode”不是有效的 JSX 元素 - 'ReactNode' is not a valid JSX element 它的实例类型“BrowserRouter”不是有效的 JSX 元素 - Its instance type 'BrowserRouter' is not a valid JSX element 它的返回类型 'void' 不是有效的 JSX 元素 - Its return type 'void' is not a valid JSX element 自定义 React Helmet 不能用作 JSX 组件 - Custom React Helmet cannot be used as a JSX component 组件不能用作 JSX 组件。 它的返回类型'元素 | undefined' 不是有效的 JSX 元素 - Component cannot be used as a JSX component. Its return type 'Element | undefined' is not a valid JSX element “X”不能用作 JSX 组件。 它的返回类型 'Element[]' 不是有效的 JSX 元素 - 'X' cannot be used as a JSX component. Its return type 'Element[]' is not a valid JSX element 组件不能用作 JSX 组件。 它的返回类型 'Element[]' 不是有效的 JSX 元素 - Component cannot be used as a JSX component. Its return type 'Element[]' is not a valid JSX element 组件不能用作 JSX 组件。 它的返回类型 'void' 不是有效的 JSX 元素(React Hooks) - Component cannot be used as a JSX component. Its return type 'void' is not a valid JSX element (React Hooks) 不能用作 JSX 组件。 它的返回类型“void”不是有效的 JSX element.ts(2786) - cannot be used as a JSX component. Its return type 'void' is not a valid JSX element.ts(2786)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM