【问题标题】:TypeError: Super expression must either be null or function, not undefined in ReactJS [duplicate]TypeError:超级表达式必须为空或函数,在 ReactJS 中未定义 [重复]
【发布时间】:2018-02-01 09:16:05
【问题描述】:

我尝试检查其他表明看到相同错误消息的帖子,但没有一个符合我的上下文。我是 ReactJS 的新手,我正在开发自己的项目。所以,我创建了两个文件'index.html'和'js/index.js'。

“index.html”文件包含以下代码:

<!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">

        <!--<link rel="stylesheet" type="text/css" href="css/style.css"/>-->
        <title>Profile</title>
        <script crossorigin src="https://unpkg.com/react@15/dist/react.min.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script>
        <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

    </head>
    <body>
        <div id="app">

        </div>
    </body>
    <script src = "js/index.js" type="text/babel"></script>
</html>

“js/index.js”文件包含:

class Card extends React.component{
    render(){
        return(
            <div className="card">
            <div className="imagebox">
                   <img src = "2.jpg"/> 
            </div>
            <div className = "biobox">
                <p>Display Name</p>
                <p>Username</p>
                <p>Location</p>
            </div>
            <div>
                <p>Updates</p>
            </div>
            </div>
        )
    }
}

ReactDOM.render(
    <Card />, document.getElementById('app')
);

我不知道我收到错误的这段代码有什么问题。

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    刚刚发现错误在'index.js'文件中。代码应该是:

    class Card extends React.Component{}
    

    【讨论】:

    • 这正是那个副本所说的。这是该错误的第一个 Google 结果。
    【解决方案2】:

    你忘记写构造函数了?

    constructor(props) {
        super(props);
    }
    

    我认为React.component 应该是React.Component。没有?

    【讨论】:

    猜你喜欢
    • 2018-02-19
    • 2018-01-21
    • 2017-07-11
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    相关资源
    最近更新 更多