简体   繁体   English

将 react-helmet 添加到我的 Gatsby 项目中会导致错误:元素类型无效

[英]Adding react-helmet into my Gatsby project causes an error: Element type is invalid

I have a component Layout which I used to style the layout of my app and that's where I introduced react-helmet我有一个组件Layout ,我用它来设置我的应用程序布局的样式,这就是我介绍react-helmet的地方

The component is like this组件是这样的


import React from 'react';
import { Global, css } from '@emotion/core';
import Helmet from 'react-helmet';
import Header from '../components/header';

const Layout = ({ children }) => (
  <>
    <Global
      styles={css`
        // some CSS style
    />

    <Helmet>
      <html lang="en" />
      <title>title</title>
      <meta name="description" content="site description" />
    </Helmet>

    <Header />
    <main
      css={css`
       // some css
      `}
    >
      {children}
    </main>
  </>
);

export default Layout;

After I added <Helmet /> , I have this error poppin up.添加<Helmet />后,我弹出了这个错误。 And if I removed <Helmet /> from my component, the error would be gone.如果我从组件中删除<Helmet /> ,错误就会消失。 apparently I didn't forgot to export my Layout component so I really have no idea where this came from.显然我没有忘记导出我的Layout组件,所以我真的不知道这是从哪里来的。

在此处输入图像描述

You need to use named import with react-helmet .您需要将命名导入与react-helmet一起使用。

import {Helmet} from "react-helmet";

Docs: https://github.com/nfl/react-helmet#example文档: https://github.com/nfl/react-helmet#example

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM