-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLab8(EventsWithEs6) copy.html
57 lines (55 loc) · 1.45 KB
/
Lab8(EventsWithEs6) copy.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>React tutorial</title>
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.2/browser.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
class FirstComponent extends React.Component {
constructor() {
super();
this.state = {
count: 0,
};
}
updateCount() {
this.setState((prevState, props) => {
return {
count: prevState.count + 1
}
});
}
componentDidUpdate() {
console.log("ES6 update");
}
componentDidUpdate(prevProps, prevState) {
if (prevState.count !== this.state.count) {
console.log('count state has changed.')
}
}
componentDidMount() {
console.log("Mount by ES6");
}
render() {
return (
<div>
<button onClick={() => this.updateCount()}>
Clicked {this.state.count} times
</button><br/>
<h1>Hello World</h1>
</div>
)
}
}
ReactDOM.render(
<FirstComponent name="Shiv"/>,
document.getElementById('app')
);
</script>
</body>
</html>