React TypeError:没有'new'就不能调用类构造函数Fullpage [英] React TypeError: Class constructor Fullpage cannot be invoked without 'new'

查看:38
本文介绍了React TypeError:没有'new'就不能调用类构造函数Fullpage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用如下所示的标记时,出现此错误!

<块引用>

React TypeError:类构造函数 Fullpage 不能在没有 'new' 的情况下被调用

看起来第 1438 行出了点问题:renderWithHooksnode_modules/react-dom/cjs/react-dom.development.js:14803这是我的 Fullpage.js 文件:

 import React, {Component} from 'react';导入'./Fullpage.css'class Fullpage 扩展 Comment{使成为(){const {children}=this.props返回(<div className={`fullpage ${this.props.className ||''}`}>{孩子们}

);}}导出默认整页

App.js 文件:

import React, { Component } from 'react'从'./data.json'导入数据;从'./logo.svg'导入标志;导入'./App.css';从'react-social-icons' 导入 { SocialIcon };从 './components/Fullpage.js' 导入 Fullpage类 App 扩展组件{使成为(){返回(<div className="应用程序容器"><div className="导航">

<Fullpage className="first"><h1 className="title";id={标题"}>{数据.title}<div><h2>{data.subtitle}

<div className="icons-wrapper">{Object.keys(data.links).map(key=>{返回(<div className="icon"><SocialIcon url={data.links[key]}/>

);})}

</整页><div className="fullpage"><h3>{data.sections[0].title}<p>{data.sections[0].items[0].content}</p>

<div className="fullpage">

);}}导出默认应用程序;

解决方案

看起来应该是:class Fullpage extends Component 而不是 Comment.

When I use tag as shown below, I'm getting this error!

React TypeError: Class constructor Fullpage cannot be invoked without 'new'

It looks like something went wrong in line 1438: renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:14803 this is my Fullpage.js file:

 import React, {Component} from 'react';
    import './Fullpage.css'
    
    class Fullpage extends Comment{
        render(){
            const {children}=this.props
            return(
                <div className={`fullpage ${this.props.className || ''}`}>
                    {children}
                </div>
            );
        }
        
    }
    
    export default Fullpage

App.js file:

import React, { Component } from 'react'
import data from './data.json';
import logo from './logo.svg';
import './App.css';
import { SocialIcon } from 'react-social-icons';
import Fullpage from './components/Fullpage.js'

class App extends Component{
    render(){
        return(
          <div className="App container">
              <div className="navigation">
              </div>
              <Fullpage className="first">
                  <h1 className="title" id={"title"}>
                      {data.title}
                  </h1>
                  <div>
                      <h2>
                        {data.subtitle}
                      </h2>
                  </div>

                  <div className="icons-wrapper">
                      {
                          Object.keys(data.links).map(key=>{
                              return(
                                  <div className="icon">
                                  <SocialIcon url={data.links[key]}/>
                                  </div>
                              );
                          })
                      }
                  </div>
              </Fullpage>
              <div className="fullpage">
                  <h3>
                      {data.sections[0].title}
                  </h3>
                  <p>
                      {data.sections[0].items[0].content}
                  </p>
              </div>
              <div className="fullpage">
              </div>
          </div>
        );
    }
}
export default App;

解决方案

Looks like there should be: class Fullpage extends Component not Comment.

这篇关于React TypeError:没有'new'就不能调用类构造函数Fullpage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆