react-qr-scanner vs react-qr-code vs react-qr-reader
React QR Code Libraries
react-qr-scannerreact-qr-codereact-qr-reader

React QR Code Libraries

These libraries provide functionalities for generating and reading QR codes within React applications. They cater to different use cases, such as creating QR codes for sharing information or scanning QR codes for fetching data. Each library has its unique features and use cases, making them suitable for various scenarios in web development involving QR codes.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-qr-scanner11,264-2.1 MB--ISC
react-qr-code086713.8 kB148 months agoMIT
react-qr-reader01,1554.38 MB150-MIT

Feature Comparison: react-qr-scanner vs react-qr-code vs react-qr-reader

QR Code Generation

  • react-qr-scanner:

    react-qr-scanner is primarily focused on scanning QR codes, but it can also be used in conjunction with other libraries to generate QR codes. It excels in providing a seamless user experience for scanning.

  • react-qr-code:

    react-qr-code allows developers to generate QR codes effortlessly with customizable options such as size, color, and error correction levels. It is designed for simplicity, making it easy to integrate into any React component without complex configurations.

  • react-qr-reader:

    react-qr-reader does not focus on QR code generation but rather on reading and interpreting QR codes. Therefore, it does not provide generation features, making it less suitable if you need to create QR codes.

Scanning Capabilities

  • react-qr-scanner:

    react-qr-scanner provides advanced scanning capabilities with real-time scanning and camera access. It is optimized for mobile devices and can handle various QR code formats, making it ideal for applications that require quick and efficient scanning.

  • react-qr-code:

    react-qr-code does not include scanning capabilities, as its main function is to generate QR codes. It is not suitable for applications requiring QR code scanning.

  • react-qr-reader:

    react-qr-reader offers robust scanning capabilities, supporting both camera and file input for scanning QR codes. It provides a simple API that makes it easy to implement scanning features in your application.

Ease of Use

  • react-qr-scanner:

    react-qr-scanner has a slightly steeper learning curve due to its advanced features, but it is still manageable for developers familiar with React. The documentation provides guidance on implementing its more complex functionalities.

  • react-qr-code:

    react-qr-code is very easy to use, with a straightforward API that allows developers to generate QR codes with minimal setup. It is perfect for developers looking for a quick solution without extensive configuration.

  • react-qr-reader:

    react-qr-reader is also user-friendly, with clear documentation and examples that help developers implement QR code scanning quickly. Its simple interface makes it accessible for developers of all skill levels.

Performance

  • react-qr-scanner:

    react-qr-scanner is designed for high performance in scanning scenarios, utilizing WebRTC for real-time camera access. It is optimized for mobile devices, ensuring quick and efficient scanning even in challenging conditions.

  • react-qr-code:

    react-qr-code is lightweight and performs well for generating QR codes without significant overhead, making it suitable for applications where performance is critical.

  • react-qr-reader:

    react-qr-reader is optimized for performance, providing quick scanning capabilities with minimal lag. It efficiently handles camera input and can process QR codes rapidly, ensuring a smooth user experience.

Customization Options

  • react-qr-scanner:

    react-qr-scanner allows some customization of the scanning interface but is primarily focused on functionality. Developers can adjust settings related to scanning behavior but have fewer options for visual customization.

  • react-qr-code:

    react-qr-code offers extensive customization options for the generated QR codes, allowing developers to modify colors, sizes, and error correction levels to match their application's design.

  • react-qr-reader:

    react-qr-reader provides limited customization options, focusing primarily on the scanning process rather than QR code appearance. It is more about functionality than design.

How to Choose: react-qr-scanner vs react-qr-code vs react-qr-reader

  • react-qr-scanner:

    Opt for react-qr-scanner if you require a more advanced scanning solution that includes features like camera access and real-time scanning capabilities. This library is ideal for applications that need to scan QR codes quickly and efficiently, especially in mobile environments.

  • react-qr-code:

    Choose react-qr-code if your primary need is to generate QR codes easily and customize their appearance. It is lightweight and straightforward, ideal for applications that require quick QR code generation without additional scanning features.

  • react-qr-reader:

    Select react-qr-reader if you need a robust solution for scanning QR codes with a simple interface. It is suitable for applications where scanning QR codes is a primary function, providing a reliable and responsive scanning experience across devices.

README for react-qr-scanner

npm version

Introduction

A React component for reading QR codes from the webcam. It uses the WebRTC standards for reading webcam data and jsQR is used for detecting QR codes in that data. To optimise the speed and experience, a web-worker is used to offload the heavy QR code algorithm on a separate process. The web worker is inlined and loaded on creation of the component. Thanks to initial repo https://github.com/JodusNodus/react-qr-reader

Demo

kybarg.github.io/react-qr-scanner/

Known Issues

  • Due to browser implementations the camera can only be accessed over https or localhost.
  • Not compatible with macOS/iOS Safari. Use legacyMode to support these platforms.
  • In Firefox a prompt will be shown to the user asking which camera to use, so facingMode will not affect it.

Install

npm install --save react-qr-scanner

Example

import React, { Component } from 'react'
import QrReader from 'react-qr-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>
    )
  }
}

Props

onScan

Type: function, Required, Argument: result

Scan event handler. Called every scan with the decoded value or null if no QR code was found.

onError

Type: function, Required, Argument: error

Function to call when an error occurs such as:

  • Not supported platform
  • The lack of available devices

onLoad

Type: function, Optional

Called when the component is ready for use.

onImageLoad

Type: function, Optional, Argument: React img onLoad event

Called when the image in legacyMode is loaded.

delay

Type: number, Optional, Default: 500

The delay between scans in milliseconds. To disable the interval pass in false.

facingMode

Type: string, Optional

Specify which camera direction should be used (if available). Options: front and rear.

legacyMode

Type: boolean, Optional, Default: 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

Type: number, Optional, Default: 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

Type: object, Optional

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

Type: string, Optional

ClassName for the container element.

chooseDeviceId

Type: function, Optional, Arguments: (1) video devices matching facingMode, (2) all video devices

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.

initialStream

Type: MediaStream, Optional

Existing MediaStream to use initially.

Dev

Install dependencies

npm install

Build

npm run build

Demo

npm run storybook

Test

npm test

Linting

npm run lint

Tested platforms

  • Chrome 56 and Firefox 53 on macOs 10.12
  • Chrome 55 and Firefox 50 on Android 6.0.1

License

The MIT License (MIT)

Copyright (c) 2017 Thomas Billiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.