<BatterySensor>

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 {

}

results matching ""

    No results matching ""