https://github.com/blackboxvision/use-torch-light
🔦Hook to enable/disable the camera torchlight via Web APIs
https://github.com/blackboxvision/use-torch-light
camera camera-flash library react react-hook react-hooks torchlight
Last synced: 5 days ago
JSON representation
🔦Hook to enable/disable the camera torchlight via Web APIs
- Host: GitHub
- URL: https://github.com/blackboxvision/use-torch-light
- Owner: BlackBoxVision
- License: mit
- Created: 2020-03-24T02:54:51.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T22:00:32.000Z (about 2 years ago)
- Last Synced: 2025-05-09T15:38:43.700Z (10 days ago)
- Topics: camera, camera-flash, library, react, react-hook, react-hooks, torchlight
- Language: TypeScript
- Homepage:
- Size: 950 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UseTorchLight [](https://badge.fury.io/js/%40blackbox-vision%2Fuse-torch-light) [](https://opensource.org/licenses/MIT) [](https://snyk.io/test/github/blackboxvision/use-torch-light)
🔦 **useTorchLight** is a hook to enable/disable camera flash. Check out the [demo](https://zittu.csb.app).
## Install
You can install this library via NPM or YARN.
### NPM
```bash
npm i @blackbox-vision/use-torch-light
```### YARN
```bash
yarn add @blackbox-vision/use-torch-light
```## Warning
**useTorchLight** relies on [ImageCapture API](https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture) whose spec isn't complete at all browsers currently. You can check the state of ImageCapture in browsers [here](https://caniuse.com/#search=imagecapture).
**We're currently trying to make the hook most consistent as possible by providing cross-browser checks and dispatching errors or alerts via success and error callbacks.**
## Usage
The usage is really simple:
```javascript
import React, { useState, useRef } from 'react';
import { QrReader } from '@blackbox-vision/react-qr-reader';
import { useTorchLight } from '@blackbox-vision/use-torch-light';const Test = (props) => {
const streamRef = useRef(null);const [error, setError] = useState(null);
const [data, setData] = useState('No result');const [on, toggle] = useTorchLight(streamRef.current);
const setRef = ({ stream }) => {
streamRef.current = stream;
};return (
<>
{on ? 'Disable Torch' : 'Enable Torch'}
{JSON.stringify(data, null, 2)}
{JSON.stringify(error, null, 2)}
>
);
};
```## Issues
Please, open an [issue](https://github.com/BlackBoxVision/use-torch-light/issues) following one of the issues templates. We will do our best to fix them.
## Contributing
If you want to contribute to this project see [contributing](https://github.com/BlackBoxVision/use-torch-light/blob/master/CONTRIBUTING.md) for more information.
## License
Distributed under the **MIT license**. See [LICENSE](https://github.com/BlackBoxVision/use-torch-light/blob/master/LICENSE) for more information.