我尝试使用简单的函数和类组件。包含在我的 app.js 中后,功能组件部分工作正常。但我包含了类组件,它显示“typeError: Class extends value undefined is not a constructor or null in react”, 我该如何解决这个问题?我错过了任何配置?
welcome.js
import React ,{ Componet } from 'react'
class Welcome extends Componet{
render(){
return <h1> class component welcome </h1>
}
}
export default Welcome
app.js
import React, {Component} from 'react'
import './App.css';
import Greet from './components/Greet'
import Welcome from './components/Welcome';
function App() {
return (
<div className="App">
<Greet/>
<Welcome/>
</div>
);
}
export default App;
反应版
npm view react version
17.0.1
npm view react-native version
0.63.4
npm view react-scripts version
4.0.2
npm view react-dom version
17.0.1
答案 0 :(得分:1)
你有一个错字Componet
,但应该是Component
class Welcome extends Componet{