class en react code example
Example 1: class in react
class App extends Component {
constructor() {
super()
this.state = {
name: "Sally",
age: 13
}
}
render() {
return (
{this.state.name}
{this.state.age} years old
)
}
}
Example 2: react class component
class Welcome extends React.Component {
render() {
return Bonjour, {this.props.name}
;
}
}
Example 3: class component in react
class Car extends React.Component {
render() {
return Hi, I am a Car!
;
}
}
Example 4: créer composant react
1. Dans le terminal :
npx create-react-app [ nom dossier]
cd [ nom dossier]
npm start
2.désinstaller package :
npm uninstall -g create-react-app