I am using the react library "qrscan" to scan a barcode with my device camera. The problem is when I successfully scan my barcode and get a value, I cannot switch off the camera and therefore the QR continues being scanned and logs the value multiple times. How can I make it that the camera switches off and I only get the initial value from the scan?
Example of code for scanning:
const [scanning, setScanning] = useState(false);
const [scannerValue, setScannerValue] = useState('');
const onFind = (value: string) => {
setScannerValue(value);
setScanning(false);
console.log(value);
};
return (
{scanning ? (
<QRScan onFind={onFind} />
) : (
<Fragment>
<button onClick={() => setScanning(true)}>Scan</button>
<h4>value: {scannerValue}</h4>
</Fragment>
)
}
)
For some reason the QRScan component keeps working even after scanning is false.