I am trying to learn class components and I have done something wrong but don't know what.
import React from "react"
class App extends React.Component() {
constructor() {
super()
this.state = {
name: "test",
age: 31
}
}
render() {
return (
<div>
<h1>{this.state.name}</h1>
<h3>{this.state.age} years old</h3>
</div>
)
}
}
export default App
And this is the error
TypeError: Class extends value undefined is not a constructor or null
You were extending React.Component()
it should be React.Component
class App extends React.Component {
constructor() {
super();
this.state = {
name: "test",
age: 31
};
}
render() {
return (
<div>
<h1>{this.state.name}</h1>
<h3>{this.state.age} years old</h3>
</div>
);
}
}
export default App;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.