Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stevent-team/react-qr-hunter

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stevent-team/react-qr-hunter

A QR code scanner for React

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

🏹 React QR Hunter

npm version minzip size

Simple and fast QR code scanner for React, based on the JavaScript library qr-scanner.

Runs in a web worker to improve performance on slower devices.

Usage

Install the package

yarn add @stevent-team/react-qr-hunter

And use it

import { createRoot } from 'react-dom/client'
import QrHunter from '@stevent-team/react-qr-hunter'

createRoot(document.getElementById('app')).render(
  <QrHunter
    onScan={result => console.log(result.data)}
    options={{
      highlightScanRegion: true,
      highlightCodeOutline: true,
    }}
  />
)

Options

The QrHunter component accepts 3 properties, onScan, onError, and options. The first two are functions that are called every frame. If no QR code is detected, the onError function will fire. By default it won't do anything. If a QR code is detected, the data and corner positions will be passed to the onScan function.

The options prop is an object that supports the following options:

OptionTypeDefaultDescription
preferredCamerastringenvironmentCan be a device ID or a facing mode (environment or user)
maxScansPerSecondnumber25This is capped by the camera's frame rate. You can change this to reduce battery consumption if you don't need as many scans.
calculateScanRegionfunctionNoneA function that is passed the video element, and should return an object with x, y, width, and height. This defines the region of the video that is processed, and can be reduced in size to improve performance. 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. Optionally you can also provide downScaledWidth and downScaledHeight in the return object to scale down the input before processing to improve performance. Note that these must be the same aspect ratio as width and height.
highlightScanRegionbooleanfalseRenders a box around the scan region. Can be styled by selecting the scan-region-highlight css class, and the scan-region-highlight-svg class for the svg box inside.
highlightCodeOutlinebooleanfalseRenders an svg polygon where it detects a QR code. Can be styled by selecting the code-outline-highlight css class.

Contributing

You can install dependencies by running yarn after cloning this repo, and yarn dev to start the demo.

This library uses changesets, if the changes you've made would constitute a version bump, run yarn changeset and follow the prompts to document the changes you've made. Changesets are consumed on releases, and used to generate a changelog and bump version number.

License

Created by Stevent and licensed under MIT

Keywords

FAQs

Package last updated on 10 Oct 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc