首页 > 解决方案 > 组件未在反应中定义

问题描述

所以我正在尝试使用 react 构建登录页面,在我的代码中我得到了未定义的错误组件。

const http = new HttpService();

class App extends Componenet {

    constructor(props) {
        super(props);
        http.getProducts();
    }
}

不知道我做错了什么,因为我是新来的反应会喜欢一些帮助

标签: reactjscomponents

解决方案


你是Component从 react 导入的吗?

如果不是 - 像这样导入

import React, {Component} from 'react';
class App extends Component{}

或者直接这样使用

class App extends React.Component{}

注意-您导入的是 Componenet 而不是 Component,只需更改为 Component。


推荐阅读