Socket
Book a DemoInstallSign in
Socket

@thewirv/react-barcode-scanner

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thewirv/react-barcode-scanner

A React component for scanning QR codes and other barcodes via webcam

3.4.0
latest
Source
npmnpm
Version published
Weekly downloads
185
-12.32%
Maintainers
1
Weekly downloads
 
Created
Source

React Barcode Scanner npm version License: MIT Known Vulnerabilities

:rocket: React Barcode Scanner component.

Table of contents

Use Case

You need a component for scanning QR codes or other barcodes from a web browser based app.

Compatibility

This component has been tested in the following browsers:

  • Chrome Mac OS & Android
  • Firefox Mac OS & Android
  • Safari Mac OS & iOS

Since this library does internal use of hooks you need React >= 16.8.0.

This library utilizes the ZXing library and therefore supports all their supported formats of 1D and 2D barcodes.

Installation

You can install this library via bun, pnpm, yarn, or npm.

bun

bun add @thewirv/react-barcode-scanner

pnpm

pnpm add @thewirv/react-barcode-scanner

yarn

yarn add @thewirv/react-barcode-scanner

npm

npm i --save @thewirv/react-barcode-scanner

Example Usage

After reading and performing the previous steps, you should be able to import the library and use it like in this example:

import {useState} from 'react';
import {BarcodeScanner} from '@thewirv/react-barcode-scanner';

function Test(props: Props) {
  const [data, setData] = useState('No result');

  return (
    <>
      <BarcodeScanner
        onSuccess={(text) => setData(text)}
        onError={(error) => {
          if (error) {
            console.error(error.message);
          }
        }}
        onLoad={() => console.log('Video feed has loaded!')}
        containerStyle={{width: '100%'}}
      />
      <p>{data}</p>
    </>
  );
}

Component API

The BarcodeScanner component has the following props:

PropertiesTypesDefault ValueRequiredDescription
doScanbooleantrueControls whether the scanner should be scanning or not
constraintsMediaTrackConstraints{ facingMode: 'user' }Specify which camera should be used (if available)
onSuccess(text: string) => voidnone🗹Callback for retrieving the result
onError(e?: Error) => voidnone🗹Callback for retrieving the error if one occurs
onLoad() => voidnoneCallback for when the camera feed has been loaded
ViewfinderReact.ReactElementnoneViewfinder component to render on top of the video element
containerStyleReact.CSSPropertiesnoneStyle object for the whole component's wrapping section element
videoContainerStyleReact.CSSPropertiesnoneStyle object for the video's container div element
videoStyleReact.CSSPropertiesnoneStyle object for the video element
videoPropsEither object of type VideoHTMLAttributes<HTMLVideoElement> or function that returns such an object and gets passed the default values set by this packageCheck defaultVideoProps inside src/BarcodeScanner/index.tsxPassed to the underlying video element

Maintainers (latest to earliest)

Browser Support

If you need to support older browsers, checkout this guide in how to make it compatible with legacy ones

Issues

Please, open an issue following one of the issues templates. We will do our best to fix them.

License

Distributed under the MIT license. See LICENSE for more information.

Keywords

react

FAQs

Package last updated on 17 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.