constructor(props) { super(props); 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: what is super(props) in react
class App extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return <div>Hello world</div>;
}
};
Example 3: what is super(props) in react
class MyComponent extends React.Component {
constructor() {
console.log(this);
}
render() {
return <div>Hello {this.props.name}</div>;
}
}