fn
useBattery
v0.0.15testeddemoReactive Battery Status API. Tracks the device charging state, charge level, and the estimated charging/discharging times, keeping them in sync with the underlying `BatteryManager` events.
Examples
ts
const { charging, level, chargingTime, dischargingTime } = useBattery();ts
// React to acquisition failures
const { isSupported } = useBattery({ onError: (e) => report(e) });Demo
Loading demo…
Signature
ts
export function useBattery(options: UseBatteryOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
options? | UseBatteryOptions | Options |
Returns
UseBatteryReturnReactive support flag, charging state, charging/discharging times, and level