# `useBattery`
React sensor hook that tracks battery status.
>**Note:** current `BatteryManager` API state is obsolete.
>Although it may still work in some browsers, its use is discouraged since it could be removed at any time.
## Usage
```jsx
import {useBattery} from 'react-use';
const Demo = () => {
const batteryState = useBattery();
if (!batteryState.isSupported) {
return (
Battery sensor: not supported
);
}
if (!batteryState.fetched) {
return (
Battery sensor: supported
Battery state: fetching
);
}
return (
Battery sensor: supported
Battery state: fetched
Charge level: { (batteryState.level * 100).toFixed(0) }%
Charging: { batteryState.charging ? 'yes' : 'no' }
Charging time:
{ batteryState.chargingTime ? batteryState.chargingTime : 'finished' }
Discharging time: { batteryState.dischargingTime }
);
};
```
## Reference
```ts
const {isSupported, level, charging, dischargingTime, chargingTime} = useBattery();
```
- **`isSupported`**_`: boolean`_ - whether browser/devise supports BatteryManager;
- **`fetched`**_`: boolean`_ - whether battery state is fetched;
- **`level`**_`: number`_ - representing the system's battery charge level scaled to a value between 0.0 and 1.0.
- **`charging`**_`: boolean`_ - indicating whether or not the battery is currently being charged.
- **`dischargingTime`**_`: number`_ - remaining time in seconds until the battery is completely discharged and the system will suspend.
- **`chargingTime`**_`: number`_ - remaining time in seconds until the battery is fully charged, or 0 if the battery is already fully charged.