forked from krambertech/react-essential-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
46 lines (40 loc) · 1.26 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Timer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
</head>
<body>
<div id='mount-point'></div>
<script type="text/babel">
var Timer = React.createClass({
getInitialState: function() {
return {
seconds: 0
};
},
componentDidMount: function() {
this.timer = setInterval(this.tick, 1000);
},
tick: function() {
this.setState({ seconds: this.state.seconds + 1 });
},
componentWillUnmount: function() {
clearInterval(this.timer);
},
render: function() {
return (
<h4> Уже прошло {this.state.seconds} секунд </h4>
);
}
});
ReactDOM.render(
<Timer />,
document.getElementById('mount-point')
);
</script>
</body>
</html>