1import React from 'react';
2import { View, TextInput } from "react-native";
3
4class App extends React.Component {
5 constructor(props){
6 super(props);
7 this.state = {
8 name: ""
9 }
10 this.handleChange = this.handleChange.bind(this);
11 }
12 handleChange(text){
13 this.setState({ name: text })
14 console.log(this.props);
15 }
16 render() {
17 return (
18 <View>
19 <TextInput
20 value={this.state.name}
21 onChangeText={(text) =>this.handleChange(text)}
22 />
23 </View>
24 }
25}
26export default App;
1class Clock extends React.Component {
2 constructor(props) {
3 super(props);
4 this.state = {date: new Date()};
5 }
6
7 componentDidMount() { }
8 componentWillUnmount() { }
9 render() {
10 return (
11 <div>
12 <h1>Hello, world!</h1>
13 <h2>It is {this.state.date.toLocaleTimeString()}.</h2>
14 </div>
15 );
16 }
17}
1class Test extends React.Component {
2 constructor() {
3 console.log('Constructor')
4 super();
5 this.state = {
6 count: 0
7 };
8 }
9
10 componentDidMount() {
11 console.log("component did mount");
12 }
13 componentDidUpdate() {
14 console.log("component did update");
15 }
16
17 onClick = () => {
18 this.setState({ count: this.state.count + 1 });
19 };
20 render() {
21 console.log("render");
22 return (
23 <div>
24 Hello Test
25 <button onClick={this.onClick}>
26 {this.state.count}
27 </button>
28 </div>
29 );
30 }
31}
32
33
34//--for first time
35//Constructor
36//render
37//component did mount
38//--for any update
39//render
40//component did update