Skip to content

Latest commit

 

History

History
66 lines (43 loc) · 1.26 KB

BatterySensor.md

File metadata and controls

66 lines (43 loc) · 1.26 KB

<BatterySensor>

React Universal Interface

Uses Navigator.getBattery() API to track battery level, charging status and time it takes to charge/discharge a battery.

Props

None.

Example

import {BatterySensor} from 'libreact/lib/BatterySensor';

<BatterySensor>{(battery) =>
  JSON.stringify(battery, null, 4)
}</BatterySensor>

Result

{
    "charging": true,
    "level": 0.98,
    "chargingTime": 2040,
    "dischargingTime": null
}

withBattery()

Higher order component that injects battery prop into your component.

import {withBattery} from 'libreact/lib/BatterySensor';

const MyCompWithBattery = withBattery(MyComp);

Overwrite the inject prop name

const MyCompWithBattery = withBattery(MyComp, 'myBattery');

or merge the props

const MyCompWithBattery = withBattery(MyComp, null);

@withBattery

Stateful component class decorator that injects battery prop into your component.

import {withBattery} from 'libreact/lib/BatterySensor';

@withBattery
class MyComp extends Component {

}