-
Notifications
You must be signed in to change notification settings - Fork 35
/
useBattery.demo.tsx
49 lines (44 loc) 路 1 KB
/
useBattery.demo.tsx
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
import { useBattery } from './useBattery';
const Demo = () => {
const battery = useBattery();
if (!battery.supported) {
return (
<p>
Battery sensor:
<code>not supported</code>
</p>
);
}
if (battery.loading) {
return (
<>
<p>
Battery sensor: <code>supported</code>
</p>
<p>
Battery state: <code>fetching</code>
</p>
</>
);
}
return (
<>
<p>
Battery sensor: <code>{battery.supported && 'supported'}</code>
</p>
<p>
Charge level: <code>{battery.level && (battery.level * 100).toFixed(0)}%</code>
</p>
<p>
Charging: <code>{battery.charging ? 'yes' : 'no'}</code>
</p>
<p>
Charging time: <code>{battery.chargingTime ? battery.chargingTime : 'finished'}</code>
</p>
<p>
Discharging time: <code>{battery.dischargingTime ? battery.dischargingTime : 'never'}</code>
</p>
</>
);
};
export default Demo;