class in react js code example
Example 1: react native class component constructor
import React from 'react';
import { View, TextInput } from "react-native";
class App extends React.Component {
constructor(props){
super(props);
this.state = {
name: ""
}
this.handleChange = this.handleChange.bind(this);
}
handleChange(text){
this.setState({ name: text })
console.log(this.props);
}
render() {
return (
this.handleChange(text)}
/>
}
}
export default App;
Example 2: 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 3: create react component class
class MyComponent extends React.Component{
constructor(props){
super(props);
};
render(){
return(
My First React Component!
);
}
};
Example 4: class app extends component syntax
class Welcome extends React.Component {
render() {
return Hello, {this.props.name}
;
}
}
Example 5: create-react-app class component
npx create-react-app my-app --scripts-version [email protected]
Example 6: react component example
const element = ;