useBattery
Hook for getting information about battery status
browser
low
test coverage
Last changed: 6 months ago
Installation
Library
CLI
Manual
typescript
import { useBattery } from '@siberiacancode/reactuse';Usage
typescript
## Demo const { supported, loading, charging, chargingTime, dischargingTime, level } = useBattery();Api
Returns
UseBatteryStateReturn
Type declaration
typescript
export interface BatteryManager extends EventTarget {
charging: boolean;
chargingTime: number;
dischargingTime: number;
level: number;
}
interface Navigator {
readonly getBattery: () => Promise<BatteryManager>;
}
export interface UseBatteryValue {
/** Is charging battery? */
charging: boolean;
/** Time until the battery is fully charged */
chargingTime: number;
/** Time until the battery is completely discharged */
dischargingTime: number;
/** Battery charge level from 0 to 1 */
level: number;
/** Is battery information loading? */
loading: boolean;
}
export interface UseBatteryStateReturn {
/** Whether the battery api is supported*/
supported: boolean;
/** The use battery value type */
value: UseBatteryValue;
}Source
Source • DemoContributors
D
B
H
N
G