简体   繁体   English

元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:对象。 ReactJS

[英]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. 起初,我认为Layout是保留名称,所以我对其进行了更改,但仍然遇到相同的错误。

App.js 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 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: 其次,使您在Layout组件中使用正确的导入语义:

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

instead of 代替

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

暂无
暂无

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

相关问题 元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:object。abcd - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. abcd 错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:ReactJS 中的对象 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object in ReactJS 元素类型无效:应为字符串(用于内置组件)或类/函数(用于复合组件)但得到: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 - 元素类型无效:需要字符串(用于内置组件)或类/函数(用于复合组件)但得到 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:错误 - 元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到: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