1.0.3 • Published 3 months ago

reactjs-qr-code-reader v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

React QrCode Reader

Read QrCodes with the user's camera. Simple, customizable. Implements zxing-js/browser.

Check out the Storybook!


Table of Contents

  1. Installation
  2. Usage
  3. Components Props
  4. License

Installation

npm install react-qr-code-reader

Usage

Just import it and done!

import { QrReader } from 'react-qr-code-reader'

export function SomeComponent() {
  const [read, setRead] = useState(true);
	
  return (
    <QrReader read={read} />
  )
}

If a guide to the QrReader is needed, you can import QrReaderViewFinder and pass it to <QrReader /> children.

import { QrReader, QrReaderViewFinder } from 'react-qr-code-reader'

export function SomeComponent() {
  const [read, setRead] = useState(true);
	
  return (
    <QrReader read={read}>
      <QrReaderViewFinder />
    </QrReader>
  )
}

If you need a fully customized guide, you can pass any React node to it!

Components Props

QrReader

PropTypeOptionalDefaultDescription
readboolean-If the reader should read.
videoConstrains[#MediaTrackConstraints (Video Tracks)]{ facingMode: 'environment', frameRate: 30 }
scanDelaynumber - ms300The delay between each reading.
scanSuccessDelaynumber - ms3500The delay to continue the reading process after a successful reading.
onReadError(err: string) => void-Function called when there is an error in the reading process.
onRead(result:Result) => void-Function called when the QrCode is read.
flipVideobooleanfalseIf the previewed video should be flipped.

It extends HTML's div attributes!

QrReaderViewFinder

PropTypeOptionalDefaultDescription
colorstringrgb(239 68 68) - redThe guide's scanning corners color.

It extends HTML's svg attributes!

Types

MediaTrackConstraints (Video Tracks)

Ref

PropType
aspectRationumber - fraction
facingModestring - user | environment | left | right
frameRatenumber - fp/s
heightnumber - px
widthnumber - px

Result

Ref

MethodReturnDescription
getTextstringText encoded on the QrCode.
getRawBytesUint8ArrayRaw bits encondded on the QrCode.
getNumBitsnumberNumber of valid bits in the Uint8Array returned by getRawBytes().
getResultPointsResultPoint[]QrCode's corners coordinates of the.
getBarcodeFormatBarcodeFormat - 11/QR_CODECode of the barcode, in this case, 11.
getTimestampnumber - timestampWhen the QrCode was read.
toStringstring

License

Licensed under the MIT License, Copyright © 2022-present WorkOS.

See LICENSE for more information.

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago