Joji
Joji

Reputation: 5615

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

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. And if I removed <Helmet /> from my component, the error would be gone. apparently I didn't forgot to export my Layout component so I really have no idea where this came from.

enter image description here

Upvotes: 2

Views: 2050

Answers (1)

Yash Joshi
Yash Joshi

Reputation: 2774

You need to use named import with react-helmet.

import {Helmet} from "react-helmet";

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

Upvotes: 6

Related Questions