R
fn

useBattery

v0.0.15testeddemo

Reactive 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

ParameterTypeDescription
options?UseBatteryOptionsOptions

Returns

UseBatteryReturnReactive support flag, charging state, charging/discharging times, and level