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

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

我有一个组件 Layout,我用它来设计我的应用程序的布局,这就是我引入 react-helmet

的地方

组件是这样的


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;

添加 <Helmet /> 后,弹出此错误。如果我从我的组件中删除 <Helmet />,错误就会消失。显然我没有忘记导出我的 Layout 组件所以我真的不知道这是从哪里来的。

您需要将命名导入与 react-helmet 一起使用。

import {Helmet} from "react-helmet";

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