forked from alexkhismatulin/react-use-count-down
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (48 loc) · 1.11 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
import React from 'react';
import ReactDOM from 'react-dom';
import useCountDown from "../src"
const buttonStyle = { marginRight: '10px' };
const App = () => {
const [timeLeft, actions] = useCountDown(10000, 500);
return (
<div style={{ textAlign: 'center' }}>
<h1 id="time-left">{(timeLeft / 1000).toFixed(2)}</h1>
<button
id="start"
style={buttonStyle}
onClick={() => actions.start()}
>
Start
</button>
<button
id="restart"
style={buttonStyle}
onClick={() => actions.start(4200)}
>
Restart with 4.2s
</button>
<button
id="pause"
style={buttonStyle}
onClick={() => actions.pause()}
>
Pause
</button>
<button
id="resume"
style={buttonStyle}
onClick={() => actions.resume()}
>
Resume
</button>
<button
id="reset"
onClick={() => actions.reset()}
>
Reset
</button>
</div>
);
};
const MOUNT_NODE = document.getElementById('react-root');
ReactDOM.render(<App />, MOUNT_NODE);