JSPM

reactjs-qr-scanner

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q31126F
  • License MIT

React.js-compatible QR code scanner component that enables easily integrate fast and reliable QR code scanning into web applications. Built with modern web APIs for camera access, it supports real-time scanning, customizable styles, and seamless integration with existing React projects.

Package Exports

  • reactjs-qr-scanner
  • reactjs-qr-scanner/dist/index.js
  • reactjs-qr-scanner/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (reactjs-qr-scanner) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

reactjs-qr-scanner

React.js-compatible QR code scanner component that enables easy integration of fast and reliable QR code scanning into web applications. Built on modern web APIs for camera access, it supports real-time scanning, customizable styles, and seamless integration with existing React projects.

📦 Dependencies

This package relies on the following libraries:

Dependency Version Description
qr-scanner ^1.4.2 A Javascript QR Code Scanner based

These dependencies will be installed automatically when you install this package.

Installation

From the project root:

  npm install reactjs-qr-scanner

usage

Import the component in your React app:

import { useState } from "react";
import ReactQrScanner from "reactjs-qr-scanner";

function App() {
  // State to control whether the scanner is paused
  const [paused, setPaused] = useState(false);

  return (
    <div className="App">
      {/* Toggle Pause Button */}
      <button onClick={() => setPaused(!paused)}>
        {paused ? "Resume" : "Pause"} Scanner
      </button>

      {/* QR Scanner Component */}
      <ReactQrScanner
        onScan={(qrdata) => {
          console.log(qrdata?.data);
        }}
        onError={(error) => {
          console.error(error);
        }}
        paused={paused}
        classNames={{
          video: "w-100",
        }}
      />
    </div>
  );
}

export default App;

Supported options are:

Option Description
onScan Callback function that is triggered when a QR code is successfully scanned. It receives the scanned data as an argument, allowing you to handle the QR code content as needed.
onError Callback invoked when the scanner or camera encounters an error. Receives an Error (or error-like) object; use it to log errors, show user-facing messages, request permissions, or provide a fallback UI.
constraints Allows customization of camera and scanning settings. Defaults to { preferredCamera: "environment", highlightScanRegion: true, highlightCodeOutline: true } when no constraints are provided. If any value is specified, defaults are not applied.
paused Pauses or resumes the QR scanner when set to true or false, respectively.
classNames Allows custom CSS class names for styling elements. For example, use classNames.video to style the video element.

constraints options:

Option Description
onDecodeError Callback triggered when a decoding error occurs. Receives the error object or message.
calculateScanRegion should be restricted as a performance improvement. This region can optionally also be scaled down before performing the scan as an additional performance improvement. The region is specified as x, y, width and height; the dimensions for the downscaled region as downScaledWidth and downScaledHeight. Note that the aspect ratio between width and height and downScaledWidth and downScaledHeight should remain the same. By default, the scan region is restricted to a centered square of two thirds of the video width or height, whichever is smaller, and scaled down to a 400x400 square.
preferredCamera Preference for the camera to be used. The preference can be either a device id as returned by listCameras or a facing mode specified as environment or user. The default is environment. Note that there is no guarantee that the preference can actually be fulfilled.
maxScansPerSecond This option can be used to throttle the scans for less battery consumption. The default is 25. If supported by the browser, the scan rate is never higher than the camera's frame rate to avoid unnecessary duplicate scans on the same frame.
highlightScanRegion Set this option to true for rendering an outline around the scan region on the video stream. This uses an absolutely positioned div that covers the scan region. This div can either be supplied as option overlay, see below, or automatically created and then accessed via qrScanner.$overlay. It can be freely styled via CSS, e.g. by setting an outline, border, background color, etc.
highlightCodeOutline Set this option to true for rendering an outline around detected QR codes. This uses an absolutely positioned div on which an SVG for rendering the outline will be placed. This div can either be supplied as option overlay, see below, or be accessed via qrScanner.$overlay. The SVG can be freely styled via CSS, e.g. by setting the fill color, stroke color, stroke width, etc.
overlay A custom div that can be supplied for use for highlightScanRegion and highlightCodeOutline. The div should be a sibling of videoElem in the DOM. If this option is supplied, the default styles for highlightCodeOutline are not applied as the expectation is that the element already has some custom style applied to it.

classNames options:

Option Description
video CSS class name applied to the video element, allowing custom styling of the scanner view.

Requirements

  • React 18 or later
  • npm (or a compatible package manager)

License

MIT License

Copyright (c) 2025 - Imran Kaleel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author

@Imran Kaleel
GitHubnpm