react componenet 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 (
<View>
<TextInput
value={this.state.name}
onChangeText={(text) =>this.handleChange(text)}
/>
</View>
}
}
export default App;
Example 2: class in react
class App extends Component {
constructor() {
super()
this.state = {
name: "Sally",
age: 13
}
}
render() {
return (
<div>
<h1>{this.state.name}</h1>
<h3>{this.state.age} years old</h3>
</div>
)
}
}
Example 3: react component example
const element = <div />;