- Hooks
- Sensors hooks
- useBattery
useBattery
Track the battery status of a user’s device with useBattery.
use-battery.tsx
Installation
Copy and paste the following code into your project.
use-battery.ts
Update the import paths to match your project setup.
Return values
Name | Type | Description |
---|---|---|
isSupported | boolean | Indicates whether the Battery Status API is supported in the user’s browser. |
isLoading | boolean | Indicates if the battery information is still loading. |
isCharging | boolean | Represents whether the system’s battery is charging. true means the battery is charging, false means it’s not. |
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. |
chargingTime | number | Represents the time remaining in seconds until the system’s battery is fully charged. |
dischargingTime | number | Represents the time remaining in seconds until the system’s battery is completely discharged and the system is about to be suspended. |