useBattery
A React Hook that get Battery state with ease.
Demo
Unplug or Insert your charger to observe the state change.
SourceYour device does not support the Battery API.
Usage
See API for more details.
Source
Click links below to view source on GitHub.
API
const battery = useBattery()
Returns
export interface UseBatteryReturns {
/**
* Whether the battery is charging
*/
charging: boolean
/**
* The battery level as a floating point number between 0 and 1
*/
level: number
/**
* The time remaining to charge the battery fully
*/
chargingTime: number
/**
* The time remaining to discharge the battery fully
*/
dischargingTime: number
/**
* Whether the battery API is supported
*/
isSupported: boolean
/**
* Update the battery state
*/
update(): void
}