useBattery
Tracking the battery status of the device.
Installation
Install the custom hook from your command line.
npm i @raddix/use-battery
Usage
API
Return
The hook returns an object with the following properties:
Name | Description | Type |
---|---|---|
isSupported | Indicates whether the Battery Status API is supported in the user’s browser. | boolean |
isLoading | Indicates if the battery information is still loading. | boolean |
level | 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. | number |
charging | Indicates whether the system’s battery is charging. true means the battery is charging, false means it’s not. | boolean |
chargingTime | Represents the time remaining in seconds until the system’s battery is fully charged. | number |
dischargingTime | Represents the time remaining in seconds until the system’s battery is completely discharged and the system is about to be suspended. | number |