useBatteryStatus

A hardware-integration hook that provides real-time access to the system's battery levels, charging state, and timing estimates.

Caution

This API is deprecated in several browsers (including Firefox) due to privacy and fingerprinting concerns. Its availability may vary across different environments.

Important

Access to battery information is only allowed in Secure Contexts (HTTPS).

Installation

bash

Description

The useBatteryStatus hook with the native Web Battery Status API to retrieve live telemetry from the device's battery. It monitors charging status, current energy levels, and provides estimates for full charge or discharge times.

This hook is ideal for building progressive web apps (PWAs) that need to adjust behavior based on energy availability—such as pausing background synchronization, reducing animation complexity, or warning users before critical battery thresholds are met.

Return values

NameTypeDescription
isSupportedbooleanIndicates if the browser supports the Battery Status API.
battery.levelnumber | nullValue from 0.0 to 1.0 representing the charge level.
battery.chargingboolean | nullTrue if the device is currently plugged in.
battery.chargingTimenumber | nullSeconds until full charge (0 if full, Infinity if unknown).
battery.dischargingTimenumber | nullSeconds until empty (Infinity if charging or unknown).

Demo

This component is loading.

Source code

tsx