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

北战南征 提交于 2021-02-10 07:50:34

问题


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;

回答1:


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



来源:https://stackoverflow.com/questions/62862856/react-typeerror-class-constructor-fullpage-cannot-be-invoked-without-new

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!