Socket
Socket
Sign inDemoInstall

react-scanning-qr-code

Package Overview
Dependencies
12
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-scanning-qr-code

A React Component for scanning QR codes from the webcam


Version published
Maintainers
1
Created

Readme

Source

React QR Code Scanner npm version License: MIT

Table of contents

Use Case

You need a scanner component for Scanning QR codes 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.

Installation

You can install this library via NPM or YARN.

NPM

npm i react-qr-code-scanner

YARN

yarn add react-qr-code-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 React, { useState } from 'react';
import { QrScanner } from 'react-qr-code-scanner';

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

  return (
    <>
      <QrScanner
        onsuccess={(result, error) => {
          if (!!result) {
            setData(result);
          }

          if (!!error) {
            console.info(error.message);
          }
        }}
        style={{ width: '100%' }}
      />
      <p>{data}</p>
    </>
  );
};

Component API

The QrCodeScanner component has the following props:

PropertiesTypesDefault ValueDescription
constraintsMediaTrackConstraints{ facingMode: 'user' }Specify which camera should be used (if available).
onSuccessfunctionnoneScan event handler
videoIdstringvideoThe ID for the video element
scanDelaynumber500The scan period for the QR hook
ViewFindercomponentnoneViewFinder component to rendering over the video element
classNamestringnoneClassName for the container element.
containerStyleobjectnoneStyle object for the container element.
videoContainerStyleobjectnoneStyle object for the video container element.
videoStyleobjectnoneStyle object for the video element.

License

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

Keywords

FAQs

Last updated on 21 Nov 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc