const BarcodeScanner = (props) => { const { handleAction, handleClose, title } = props; const cameraRef = useRef(null); const [using, setUsing] = useState(false); useEffect(() => { const quaggaConf = { inputStream: { target: cameraRef.current, type: "LiveStream", constraints: { width: { min: 640 }, height: { min: 480 }, facingMode: "environment", // Sử dụng camera phía sau aspectRatio: { min: 1, max: 2 } } }, decoder: { readers: ['code_128_reader'] }, }; Quagga.init(quaggaConf, (err) => { if (err && using) { alert('Camera not found!'); console.error(err); return; } setUsing(true); Quagga.start(); }); Quagga.onDetected((result) => { handleAction(result); setUsing(false); Quagga.stop(); handleClose(); }); // Cleanup function to stop Quagga on component unmount return () => { Quagga.stop(); Quagga.offDetected(); setUsing(false); }; }, []); return (