-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.js
39 lines (38 loc) · 1.02 KB
/
Demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { Component } from "react";
import ShowName from "./ShowName";
class Demo extends Component {
//props can only read where state can be read and write
state = {
name: "",
address: "mumbai",
};
componentDidUpdate(prevProps, prevState, snapshot) {
console.log("componentDidUpdate called");
console.log({ prevProps, prevState, snapshot });
console.log("------------------------------");
}
componentDidMount() {
//called only once when my component get mounted
console.log("demo componet mounted..");
console.log({ currentObj: this });
console.log("------------------------------");
this.setState({
name: "default",
});
}
//1st called
render() {
const { name } = this.state;
return (
<div>
<h1>Demo Component</h1>
<h3>Hello {name}</h3>
<button onClick={() => this.setState({ name: "Imran" })}>
Get name
</button>
<ShowName name={name} address="mumbai" />
</div>
);
}
}
export default Demo;