简体   繁体   中英

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

Can't resolve this issue. Whenever I import Layout I get the error above. When I import other components they work just fine. At first I thought the name Layout was reserved so I changed it but still got the same error.

App.js

import React, { Component } from 'react';
import Layout from "./components/Layout/Layout";

class App extends Component {
  render() {
    return (
      <div>
        <Layout />
      </div>
    )
  }
}

export default App

Layout.js

import React, { Component } from 'react'
import Footer from '../Footer/Footer'
import Quotes from '../Quotes/Quotes'
import './Layout.css'

class Layout extends Component {
    render() {
        return (
            <div className='bgImg'>
                <div className='centered text-center align-items-center justify-content-center'>
                    <Quotes />
                </div>
                <Footer />
            </div>
        )
    }
}

export default Layout

错误信息

The error tells you exactly what you should do.
First, make you sure export the components properly:

/* relevant imports */

class Quotes extends Component {
  /* component code */
}

export default Quotes

Second make you use the proper import semantic in your Layout component:

import Quotes from '/path/to/your/component';

instead of

import {Quotes} from '/path/to/your/component';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. abcd Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object in ReactJS Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined in reactjs Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object How to fix Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object Error:Element type is invalid: expected a string (for built-in components)or a class/function(for composite components)but got:object React: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object Recoil Nexus - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got object NextJS: error - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM