sanity-io / sanity-template-nextjs-landing-pages

A Sanity powered landing page builder in Next.js for https://sanity.io/create
https://www.sanity.io/create/?template=sanity-io%2Fsanity-template-nextjs-landing-pages
158 stars 54 forks source link

Element type is invalid in _document.js #56

Open mariabarkouzou opened 2 years ago

mariabarkouzou commented 2 years ago

I've created the _document.js as suggested in the template but I get this error in the console:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

The code is this:

import React from 'react' import Document, {Html, Head, Main, NextScript} from 'next/document' import client from '../client'

export default class MyDocument extends Document { static async getInitialProps (ctx) { const initialProps = await Document.getInitialProps(ctx) return client.fetch('*[_id == "global-config"] {lang}.lang[0]').then(lang => { return {...initialProps, lang} }) }

render () { return (

  <Html lang={this.props.lang || 'en'}>
    <Head />
    <body>
      <Main />
      <NextScript />
    </body>
  </Html>

)

} }

Has anyone had this issue?And if yes , how did you solve it?Thank you in advance!