-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clock.jsx
44 lines (38 loc) · 1013 Bytes
/
Clock.jsx
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
/*****************************
* A digital Clock Component. *
* Author: Nikos-Nikitas *
******************************/
import React from 'react';
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {
date: new Date()
};
}
//if the component mounts it starts the clock ticking, if it unmounts the ticking stops.
componentDidMount() {
this.tID = setInterval(
() => this.moveTime(),
1000
);
}
componentWillUnmount() {
clearInterval(this.tID);
}
moveTime() {
this.setState(
{
date: new Date()
}
);
}
//styling using className for css class.
render() {
return (
<div className="the_clock">
<h2 className="the_clock"> <b> {this.state.date.toLocaleTimeString()} </b></h2>
</div>
);
}
}