您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页react引用其他组件Error: Element type is invalid: expected a string (for built-in components) or a class/fu

react引用其他组件Error: Element type is invalid: expected a string (for built-in components) or a class/fu

来源:好走旅游网

报错详情如下

Error: Element type is invalid: expected a string (for built-in
 components) or a class/function (for composite components) but
  got: undefined. You likely forgot to export your component from 
  the file it's defined in, or you might have mixed up default and 
  named imports.

home文件如下

import React from 'react'
import styles from './index.css'
import Announcement from './announcement.js'


class Home extends React.Component{
    constructor(props){
        super(props)
        this.state={}
    }
    render(){
        return(
            <div className={styles.bodys}>
                aaaa
                <div>
                    <Announcement/>
                </div>
            </div>
        );
    }
}

export default Home;

announcement文件主要如下

class Announcement extends React.Component{
    

    render() {
        return(
           <div>
               <Tops/>
               <Divider />
               <List/>
           </div>
        );
    }
}

然后他就报错

原因是我没有将 Announcement 抛出
在announcement 文件下加入

export default announcement;

放一张访问正常图

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- haog.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务