Skip to content

Commit 3d5ae07

Browse files
committed
docs: update use-battery
1 parent 0e563cf commit 3d5ae07

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

content/hooks/use-battery.mdx

+11-13
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ description: Track the battery status of a user’s device with useBattery.
88
## Installation
99

1010
<Steps>
11-
<Step>
12-
Copy and paste the following code into your project.
13-
</Step>
11+
12+
<Step>Copy and paste the following code into your project.</Step>
1413

1514
```ts
16-
// title hooks/use-debounce.ts
15+
// title hooks/use-battery.ts
1716
import React from "react";
1817

1918
interface BatteryManager extends EventTarget {
@@ -90,7 +89,6 @@ export function useBattery() {
9089

9190
return state;
9291
}
93-
9492
```
9593

9694
<Step>
@@ -100,11 +98,11 @@ export function useBattery() {
10098

10199
## Return values
102100

103-
| Name | Type | Description |
104-
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
105-
| supported | boolean | Indicates whether the Battery Status API is supported in the user’s browser. |
106-
| loading | boolean | Indicates if the battery information is still loading. |
107-
| level | number | Represents the level of the system’s battery. 0.0 means that the system’s battery is completely discharged, and 1.0 means the battery is completely charged. |
108-
| charging | boolean | Represents whether the system’s battery is charging. `true` means the battery is charging, `false` means it’s not. |
109-
| chargingTime | number | Represents the time remaining in seconds until the system’s battery is fully charged. |
110-
| dischargingTime | number | Represents the time remaining in seconds until the system’s battery is completely discharged and the system is about to be suspended. |
101+
| Name | Type | Description |
102+
| ----------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
103+
| `isSupported` | `boolean` | Indicates whether the Battery Status API is supported in the user’s browser. |
104+
| `isLoading` | `boolean` | Indicates if the battery information is still loading. |
105+
| `isCharging` | `boolean` | Represents whether the system’s battery is charging. `true` means the battery is charging, `false` means it’s not. |
106+
| `level` | `number` | Represents the level of the system’s battery. 0.0 means that the system’s battery is completely discharged, and 1.0 means the battery is completely charged. |
107+
| `chargingTime` | `number` | Represents the time remaining in seconds until the system’s battery is fully charged. |
108+
| `dischargingTime` | `number` | Represents the time remaining in seconds until the system’s battery is completely discharged and the system is about to be suspended. |

src/lib/hooks/use-battery/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export function useBattery() {
2929
});
3030

3131
React.useEffect(() => {
32-
if (!(navigator as NavigatorWithBattery)) {
32+
if (!(navigator as NavigatorWithBattery).getBattery) {
3333
setState((s) => ({
3434
...s,
35-
supported: false,
36-
loading: false,
35+
isSupported: false,
36+
isLoading: false,
3737
}));
3838
return;
3939
}

0 commit comments

Comments
 (0)