weblineindia/ReactJS-QRCode-Scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReactJS based QR Code Scanner component, allowing you to detect and decode QR codes.

ChromeFirefoxSafariEdgeIE
83.0 ✔77.0 ✔13.1.1 ✔83.0 ✔Not supported

Install the npm package:

npm install react-weblineindia-qrcode-scanner
#OR
yarn add react-weblineindia-qrcode-scanner

Use the <react-weblineindia-qrcode-scanner> component:

import React, { Component } from 'react'
import QrReader from 'react-weblineindia-qrcode-scanner'

class Test extends Component {
  constructor(props){
    super(props)
    this.state = {
      delay: 100,
      result: 'No result',
    }

    this.handleScan = this.handleScan.bind(this)
  }
  handleScan(data){
    this.setState({
      result: data,
    })
  }
  handleError(err){
    console.error(err)
  }
  render(){
    const previewStyle = {
      height: 240,
      width: 320,
    }

    return(
      <div>
        <QrReader
          delay={this.state.delay}
          style={previewStyle}
          onError={this.handleError}
          onScan={this.handleScan}
          />
        <p>{this.state.result}</p>
      </div>
    )
  }
}

For Next.js Use dynamic import instead of usual import.

import dynamic from 'next/dynamic'
const QrReader = dynamic(() => import('react-weblineindia-qrcode-scanner').then((a) => a.QrReader), {ssr: false});
PropTypedefaultDescription
delaynumber500The delay between scans in milliseconds. To disable the interval pass in false.
facingModestringSpecify which camera direction should be used (if available). Options: front and rear.
legacyModebooleanfalseIf the device does not allow camera access (e.g. IOS Browsers, Safari) you can enable legacyMode to allow the user to take a picture (On a mobile device) or use an existing one. To trigger the image dialog just call the method openImageDialog from the parent component. Warning You must call the method from a user action (eg. click event on some element).
maxImageSizenumber1500If legacyMode is active then the image will be downscaled to the given value while keepings its aspect ratio. Allowing larger images will increase the accuracy but it will also slow down the processing time.
styleobjectStyling for the preview element. This will be a video or an img when legacymode is true. Warning The preview will keep its aspect ratio, to disable this set the CSS property objectFit to fill.
classNamestringClassName for the container element.
chooseDeviceIdfunctionCalled when choosing which device to use for scanning. By default chooses the first video device matching facingMode, if no devices match the first video device found is choosen.
NameDescription
onScanScan event handler. Called every scan with the decoded value or null if no QR code was found.
onErrorFunction to call when an error occurs such as:- Not supported platform -The lack of available devices
onLoadCalled when the component is ready for use.
onImageLoadCalled when the image in legacyMode is loaded.
  • Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
  • Fork it.
  • Create new branch to contribute your changes.
  • Commit all your changes to your branch.
  • Submit a pull request.

We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development


Detailed changes for each release are documented in CHANGELOG.md.

react-weblineindia-qrcode-scanner is inspired by react-qr-scanner.

MIT

react-weblineindia-qrcode-scanner, qrcode, qrcode-reader, qrcode-scanner, webrtc, react-qrcode-scanner, barcode-scanner, react-barcode, reactjs-qr-code, reactjs-barcode