Ambient Light Sensor hook for React
  • JavaScript 82.2%
  • HTML 17.8%
Find a file
dependabot[bot] bd07aa626c Bump lodash from 4.17.11 to 4.17.15
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.15.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.11...4.17.15)

Signed-off-by: dependabot[bot] <support@github.com>
2020-02-18 20:12:33 -06:00
.gitignore initial 2018-10-25 22:51:10 -05:00
.travis.yml initial 2018-10-25 22:51:10 -05:00
example.html initial 2018-10-25 22:51:10 -05:00
example.js Updating docs 2018-10-25 23:03:17 -05:00
index.d.ts initial 2018-10-25 22:51:10 -05:00
index.js Check if sensor exists before calling .stop() 2020-02-07 08:36:39 -06:00
index.js.flow initial 2018-10-25 22:51:10 -05:00
LICENSE Updating docs 2018-10-25 23:03:17 -05:00
package.json initial 2018-10-25 22:51:10 -05:00
README.md tell useEffect not to run on each render pass, added sensor.stop on unmount 2018-10-25 23:47:51 -05:00
test-setup.js initial 2018-10-25 22:51:10 -05:00
test.js Updating docs 2018-10-25 23:03:17 -05:00
yarn.lock Bump lodash from 4.17.11 to 4.17.15 2020-02-18 20:12:33 -06:00

@rehooks/light-sensor

React hook for subscribing to the readings of your device's AmbientLightSensor

Note: At the moment, browser support is thin and also requires use of Feature-Policy headers

Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.

You'll need to install react, react-dom, etc at ^16.7.0-alpha.0

Install

yarn add @rehooks/light-sensor

Usage

import useAmbientLightSensor from '@rehooks/light-sensor';

function MyComponent() {
  let lux = useAmbientLightSensor();

  if(lux == null) { return "Loading" }

  return <div>{`You're device is reading ${lux} lux`}</div>;
}