Coder Social home page Coder Social logo

weblineindia / reactjs-qrcode-scanner Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 3.0 67 KB

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

Home Page: https://www.weblineindia.com/software-development-resources.html

License: MIT License

JavaScript 100.00%
reactjs-qrcode-scanner reactjs-barcode-scanner react-qr-reader javascript-qrcode barcode-scanner qrcode-scanner qr-code-reader qr-code-decoder react-qr-scanner reactjs

reactjs-qrcode-scanner's Introduction

ReactJS - QR Code / Barcode Scanner Component

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

Table of contents

Browser Support

Chrome Firefox Safari Edge IE
83.0 ✔ 77.0 ✔ 13.1.1 ✔ 83.0 ✔ Not supported

Getting started

Install the npm package:

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

Usage

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});

Available Props

Prop Type default Description
delay number 500 The delay between scans in milliseconds. To disable the interval pass in false.
facingMode string Specify which camera direction should be used (if available). Options: front and rear.
legacyMode boolean false If 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).
maxImageSize number 1500 If 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.
style object Styling 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.
className string ClassName for the container element.
chooseDeviceId function Called 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.

Methods

Name Description
onScan Scan event handler. Called every scan with the decoded value or null if no QR code was found.
onError Function to call when an error occurs such as:- Not supported platform -The lack of available devices
onLoad Called when the component is ready for use.
onImageLoad Called when the image in legacyMode is loaded.

Want to Contribute?

  • 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.

Collection of Components

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


Changelog

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

Credits

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

License

MIT

Keywords

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

reactjs-qrcode-scanner's People

Contributors

partners-wli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

reactjs-qrcode-scanner's Issues

mobile phone not picking up "rear" facingMode

Firstly - thanks so much for providing this package!

I'm having issues with the facingMode prop - when accessing the camera on a mobile phone (iPhone or Android) and in any browser (Safari and Chrome tested), it always picks up the front facing camera.

<QrReader onError={handleError} onScan={handleScan} facingMode={'rear'} style={{ width: '100%' }} />

Any direction to making sure only rear camera is selected onLoad would be very helpful! Thanks!

Cannor use import statement outside a module

Hi,

I am having this error in NextJS and I don't know why

/home/enkdress/Documents/work/control-covid/control/node_modules/react-weblineindia-qrcode-scanner/lib/index.js:36
import React, { Component } from 'react';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at eval (webpack-internal:///react-weblineindia-qrcode-scanner:1:18)
    at Object.react-weblineindia-qrcode-scanner (/home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:171:1)
    at __webpack_require__ (/home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:23:31)
    at eval (webpack-internal:///./pages/scanQr.js:8:91)
    at Module../pages/scanQr.js (/home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:115:1)
    at __webpack_require__ (/home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:23:31)
    at Object.5 (/home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:126:18)
    at __webpack_require__ (/home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:23:31)
    at /home/enkdress/Documents/work/control-covid/control/.next/server/static/development/pages/scanQr.js:91:18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.