React hook for Ambient Light Sensor access
npm install react-hook-ambient-lightA React hook to access data from the Ambient Light API.
Using npm:
``sh`
npm install --save react-hook-ambient-light
Using yarn:
`sh`
yarn add react-hook-ambient-light
`jsx
import React from 'react'
import useAmbientLightSensor from 'react-hook-ambient-light'
const ComponentWithAccelerometer = () => {
const sensor = useAmbientLightSensor()
return !sensor.error ? (
No ambient light, sorry.
$3
If you want to use this feature, simply provide
useAmbientLightSensor with a SensorOptions object:`jsx
const sensor = useAmbientLightSensor({
frequency: 60, // cycles per second
})
``Access to data from the Ambient Light API needs user permission.
Ambient Light API is available only in secure contexts (only using HTTPS).
Credit to Bence A. Tóth for his original hook code for Geolocation.
LGPL-3.0