-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (55 loc) · 1.28 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from "./react";
import ReactDOM from "./react-dom";
const ele = (
<div className="a" title="t">
hello <span>react</span>
</div>
);
// 函数组件
function Home1() {
return ele;
}
// 类组件
class Home2 extends React.Component {
constructor(props) {
super(props);
this.state = {
num: 0,
};
this.handlerClick = this.handlerClick.bind(this);
}
componentWillMount() {
console.log("Legacy componentWillMount");
}
componentWillReceiveProps() {
console.log("Legacy componentWillReceiveProps");
}
componentWillUpdate() {
console.log("Legacy componentWillUpdate");
}
componentDidMount() {
console.log("componentDidMount");
}
componentDidUpdate() {
console.log("componentDidUpdate");
}
componentWillUnmount() {
console.log("componentWillUnmount");
}
handlerClick() {
console.log("handlerClick");
this.setState({
num: this.state.num + 1,
});
}
render() {
return (
<div className="className" title="title">
hello <span>react</span> <span>{this.state.num} </span>
<button onClick={this.handlerClick}>+</button>
</div>
);
}
}
//ReactDOM.render(ele, document.querySelector("#root"));
ReactDOM.render(<Home2 name="title" />, document.querySelector("#root"));