A React hook that provides a high-level interface for detecting barcodes and QR codes in real-time using the browser's Barcode Detection API.
Warning
The Barcode Detection API is an experimental technology. Currently, it has limited browser support, primarily available in Chromium-based browsers.
Important
Camera access requires a Secure Context (HTTPS) and explicit user permission. The start() method will trigger the browser's permission prompt.
Tip
For optimal performance, provide a specific formats list to reduce the detector's processing overhead.
Installation
bash
Description
The useBarcode hook automates the lifecycle of barcode detection. It handles camera stream initialization (using the environment/rear camera by default), executes a continuous scanning loop via requestAnimationFrame, and manages the underlying BarcodeDetector instance. It can process input from video streams, static images, or canvas elements, returning the raw data and format of the first detected barcode.