@blackbox-vision/use-torch-light
Version:
A hook to enable/disable camera flash
69 lines (47 loc) ⢠2.1 kB
Markdown
is a hook to enable/disable camera flash. Check out the [demo](https://zittu.csb.app).
You can install this library via NPM or YARN.
```bash
npm i @blackbox-vision/use-torch-light
```
```bash
yarn add @blackbox-vision/use-torch-light
```
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 (
<>
<QrReader
onLoad={setRef}
onScan={setData}
onError={setError}
style={{ width: '100%' }}
/>
<button onClick={toggle}>{on ? 'Disable Torch' : 'Enable Torch'}</button>
<p>{JSON.stringify(data, null, 2)}</p>
<p>{JSON.stringify(error, null, 2)}</p>
</>
);
};
```
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.
If you want to contribute to this project see [contributing](https://github.com/BlackBoxVision/use-torch-light/blob/master/CONTRIBUTING.md) for more information.
Distributed under the **MIT license**. See [LICENSE](https://github.com/BlackBoxVision/use-torch-light/blob/master/LICENSE) for more information.
š¦ **useTorchLight**