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

react-qrcode-scanner

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-qrcode-scanner

QR code scanner component for React apps

  • 1.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
91
decreased by-18.02%
Maintainers
1
Weekly downloads
 
Created
Source

Introduction

A React component that provides a simple and efficient way to read QR codes from a web or mobile camera. This lightweight component utilizes HTML canvas to capture images and leverages the jsQR library to detect QR codes within the image data. NOTE: HTTPS is required to use camera on mobile devices. However, you can test over localhost on your computer

DEMO

Install

npm i react-qrcode-scanner

Example

import React from 'react';
import { QrScanner } from 'react-qrcode-scanner';

function App() {
  const handleScan = (value) => {
    console.log({ value });
  };

  const handleError = (error) => {
    console.log({ error });
  };

  return (
    <div className='App'>
      <QrScanner onScan={handleScan} onError={handleError} />
    </div>
  );
}

export default App;

Props

Prop NameTypeDefault ValueDescription
onErrorFunction(error) => console.log({error})Callback function that is called when an error occurs during scanning.
onScanFunction(value) => console.log({value})Callback function that is called when a QR code is successfully scanned.
facingModeString'environment'The facing mode of the camera. Can be set to 'environment' or 'face'.
constraintsObjectnullThe device constraints for the camera.
onLoadFunction(val: {mirrorVideo, streamLabel}) => nullCallback function that is called when the component is loaded.
flipHorizontallyBooleanfalseDetermines whether the video output should be flipped or reflected based on the facing mode.
styleObjectnullAdditional styling for the section.
classNameStringnullAdditional class names for the section wrapper.
delayNumber800The delay between each scan attempt in milliseconds.
resolutionNumber600The resolution of the canvas in pixels.
aspectRatiostring'16:9'Aspect ratio of the video frame. Default is landscape. Change to '3:4' for portrait
showViewFinderBooleantrueDetermines whether to show the viewfinder.
viewFinderObject{ border: '12px solid rgba(255,255,255,0.3)', position: 'absolute', borderRadius: '5px', width: '250px', height: '250px' }Additional CSS styles for the viewfinder element.

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 15 Jun 2024

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