# react-hook-ambient-light

> React hook for Ambient Light Sensor access

Latest version **1.1.3** (published 2022-04-19) · LGPL license · 0 weekly downloads

## Install

```sh
npm install react-hook-ambient-light
pnpm add react-hook-ambient-light
yarn add react-hook-ambient-light
bun add react-hook-ambient-light
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2022-04-19 |
| First published | 2022-04-04 |
| Weekly downloads | 0 |
| License | LGPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Masao Kitamura |
| Maintainers | masao |
| Keywords | react, hook, ambient, light |

## Links

- npm: https://www.npmjs.com/package/react-hook-ambient-light
- Repository: https://github.com/masaok/react-hook-ambient-light
- Homepage: https://github.com/masaok/react-hook-ambient-light#readme
- Issues: https://github.com/masaok/react-hook-ambient-light/issues
- npm.io page: https://npm.io/package/react-hook-ambient-light

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2022-04-19
- 1.1.2 — 2022-04-19
- 1.1.1 — 2022-04-04

## README

A React hook to access data from the [Ambient Light API](https://developer.mozilla.org/en-US/docs/Web/API/AmbientLightSensor).

## Installation

Using `npm`:

```sh
npm install --save react-hook-ambient-light
```

Using `yarn`:

```sh
yarn add react-hook-ambient-light
```

## Usage

```jsx
import React from 'react'
import useAmbientLightSensor from 'react-hook-ambient-light'

const ComponentWithAccelerometer = () => {
  const sensor = useAmbientLightSensor()

  return !sensor.error ? (
    <ul>
      <li>X: {sensor.x}</li>
      <li>Y: {sensor.y}</li>
      <li>Z: {sensor.z}</li>
    </ul>
  ) : (
    <p>No ambient light, sorry.</p>
  )
}
```

### Using `SensorOptions`

If you want to use this feature, simply provide `useAmbientLightSensor` with a `SensorOptions` object:

```jsx
const sensor = useAmbientLightSensor({
  frequency: 60, // cycles per second
})
```

## Notes

Access to data from the Ambient Light API needs user permission.

## Caveats

Ambient Light API is available only in secure contexts (only using HTTPS).

## Credits

Credit to [Bence A. Tóth](https://github.com/bence-toth) for his original hook code for [Geolocation](https://www.npmjs.com/package/react-hook-geolocation).

## License

LGPL-3.0

---
_Source: https://npm.io/package/react-hook-ambient-light · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
