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