1.0.2 • Published 1 year ago

react-scan-qr-code v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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-scan-qr-code

YARN

yarn add react-scan-qr-code

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-scan-qr-code';

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.