-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
43 lines (37 loc) · 837 Bytes
/
example.js
File metadata and controls
43 lines (37 loc) · 837 Bytes
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
import React from 'react';
import { render } from 'react-dom';
import useCountdownSeconds from './';
function App() {
return <div>Behold, le app</div>;
}
function Session({ children }) {
const {
start,
startTime,
timeLeft,
isWarning
} = useCountdownSeconds(3, 2);
if (!startTime) {
return (
<div>
<button onClick={() => start(new Date())}>
Login
</button>
</div>
);
}
return (
<div>
<button onClick={() => start(0)}>
Logout
</button>
{isWarning && (
<button onClick={() => start(new Date())}>Extend Session</button>
)}
<div>Logged in since: {startTime.toLocaleString()}</div>
<div>Expires in {timeLeft} seconds</div>
{children}
</div>
);
}
render(<Session><App /></Session>, window.root);