Skip to main content
The scanner runs a detection loop against the live <video> element and fires onScan only after the same value is confirmed across multiple frames. Both react-webcam and the barcode-detector polyfill are pre-installed.

The scanner component

Using it

onScan receives (value, format). Conditionally render the scanner so it unmounts and releases the camera once a scan lands. For back-to-back scanning, remount after each hit with a changing key to reset confirmation state.

Why the defensive bits matter

  • Multi-frame confirmation (confirmations, default 2) is the biggest defense against misreads — bump to 3 for high-stakes scans.
  • Check-digit validation rejects single-character misreads on EAN-13 / EAN-8 / UPC-A for free.
  • Detect on the <video> element — ~10× faster than screenshotting to base64, no JPEG artifacts.
  • requestAnimationFrame + busy lock, not setInterval — scans at frame rate without overlapping calls.
  • HD constraints (1920×1080) — the 640×480 default can’t decode a retail barcode at arm’s length.
  • Restrict formats to what the app reads — fewer formats, fewer false positives.