What it does
The QR code scanner component accesses the device camera and continuously captures frames to decode QR codes using jsQR, a pure JavaScript QR decoder. The viewfinder overlay helps users frame the QR code correctly.
The component supports both automatic continuous scanning and single-scan mode. It also exposes a scanImage method for decoding QR codes from uploaded image files.
Composition and API
Use the required onResult callback to receive decoded data. Configure the camera with facingMode (user/environment) and additional constraints. The scanDelay prop controls the interval between frame decodes. The continuous prop determines whether scanning stops after the first result. The component exposes start, stop, and scanImage methods via ref.
Common use cases
QR code scanning is essential for mobile-friendly authentication flows, event check-ins, inventory tracking, payment verification, and any application that needs to bridge physical and digital experiences.
Accessibility
The component provides status announcements for camera state changes. The viewfinder overlay helps visually indicate the scan area. Error states provide clear feedback when camera access fails.
Next.js integration notes
Colocate examples under the App Router, keep server and client boundaries explicit, and avoid pulling interactive components into unexpected server layouts.
Set NEXT_PUBLIC_SITE_URL so canonical and Open Graph URLs resolve on deploy.
FAQ
Does the QR Scanner component work with Next.js App Router?
Yes. Import it like any other React component; the scanner uses client-side camera access and canvas processing and works seamlessly as a client boundary.
What camera permissions are needed?
The component uses navigator.mediaDevices.getUserMedia which requires camera permission. The user will be prompted to allow camera access on first use.
Can I scan from an image file?
Yes. The component exposes a scanImage method via its imperative handle that accepts a File object and returns the decoded data or null.
What happens if no camera is available?
The component gracefully falls back to a 'Camera not available' state with a customizable fallback message. It also works in environments where camera access is denied.