react-qr-code vs react-qr-reader vs react-qr-scanner
二维码处理库
react-qr-codereact-qr-readerreact-qr-scanner

二维码处理库

这些库用于在React应用中生成和读取二维码。它们提供了不同的功能和使用场景,适合不同的开发需求。使用这些库,开发者可以轻松地集成二维码的生成和扫描功能,以提升用户体验和应用的互动性。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-qr-code087314.4 kB151 天前MIT
react-qr-reader01,1544.38 MB150-MIT
react-qr-scanner0-2.1 MB--ISC

功能对比: react-qr-code vs react-qr-reader vs react-qr-scanner

二维码生成

  • react-qr-code:

    react-qr-code提供简单的API来生成静态二维码,支持自定义颜色、大小和边距,非常适合需要快速生成二维码的场景。

  • react-qr-reader:

    react-qr-reader不支持二维码生成,它主要用于二维码的扫描和读取。

  • react-qr-scanner:

    react-qr-scanner同样不支持二维码生成,专注于高效的二维码扫描。

二维码扫描

  • react-qr-code:

    react-qr-code不支持二维码扫描功能,专注于生成二维码。

  • react-qr-reader:

    react-qr-reader提供实时二维码扫描功能,支持多种设备,适合需要即时读取二维码的应用。

  • react-qr-scanner:

    react-qr-scanner提供高性能的二维码扫描功能,能够快速识别移动中的二维码,适合高频率扫描的场景。

用户体验

  • react-qr-code:

    react-qr-code的用户体验相对简单,主要集中在二维码的展示上,适合不需要复杂交互的应用。

  • react-qr-reader:

    react-qr-reader提供良好的用户体验,能够实时反馈扫描结果,适合需要用户交互的应用。

  • react-qr-scanner:

    react-qr-scanner优化了用户体验,支持快速扫描和反馈,适合需要高效扫描的应用场景。

兼容性

  • react-qr-code:

    react-qr-code兼容性良好,能够在大多数现代浏览器中正常工作。

  • react-qr-reader:

    react-qr-reader支持多种设备,包括移动设备和桌面设备,兼容性较强。

  • react-qr-scanner:

    react-qr-scanner同样支持多种设备,特别优化了移动设备的使用体验。

性能

  • react-qr-code:

    react-qr-code的性能主要取决于二维码的生成过程,适合生成静态二维码。

  • react-qr-reader:

    react-qr-reader的性能良好,能够快速扫描二维码,但在光线不足的情况下可能会受到影响。

  • react-qr-scanner:

    react-qr-scanner在性能上表现优异,能够处理快速移动的二维码,适合高频率使用的场景。

如何选择: react-qr-code vs react-qr-reader vs react-qr-scanner

  • react-qr-code:

    选择react-qr-code如果你需要一个简单的二维码生成器,能够快速生成静态二维码并在应用中展示。

  • react-qr-reader:

    选择react-qr-reader如果你需要一个功能全面的二维码扫描器,支持多种设备和相机,适合需要实时扫描的应用场景。

  • react-qr-scanner:

    选择react-qr-scanner如果你需要一个高性能的二维码扫描器,能够处理快速移动的二维码,并且希望有更好的用户体验和更高的扫描成功率。

react-qr-code的README

react-qr-code

npm package

A component for React. This library works with React and React Native (using React Native SVG).

Screenshots

Web

Android & iOS

Installation

npm i react-qr-code

When using this library with React Native, you will also need to have react-native-svg installed.

npm i react-native-svg
cd ios && pod install

The Gist

import React from "react";
import ReactDOM from "react-dom";
import QRCode from "react-qr-code";

ReactDOM.render(<QRCode value="hey" />, document.getElementById("Container"));

Note: If the QR code is likely to appear next to dark objects, you will need to wrap it in a light-colored container to preserve the 'quiet zone', e.g.

<div style={{ background: 'white', padding: '16px' }}>
  <QRCode ... />
</div>

Responsive QR code example:

// Can be anything instead of `maxWidth` that limits the width.
<div style={{ height: "auto", margin: "0 auto", maxWidth: 64, width: "100%" }}>
  <QRCode
    size={256}
    style={{ height: "auto", maxWidth: "100%", width: "100%" }}
    value={value}
    viewBox={`0 0 256 256`}
  />
</div>

API

proptypedefault valueplatform
bgColorstring'#FFFFFF'web, ios, android
fgColorstring'#000000'web, ios, android
levelstring ('L' 'M' 'Q' 'H')'L'web, ios, android
sizenumber256web, ios, android
titlestringweb
valuestringweb, ios, android

Adheres to the official QR spec and can store up to 2953 characters in value.

Non-ASCII / UTF-8 text

react-qr-code encodes data in UTF-8 byte mode to ensure non-ASCII text (e.g., Korean, Japanese, emoji) renders and scans correctly. Just pass a normal JavaScript string:

<QRCode value="한글 테스트 😊" />

No additional encoding is required on your side.

Testing UTF-8 locally

  1. Build the demo library bundle in watch mode:
    • In one terminal: npm run demo-web-watch
  2. Run the demo app:
    • In another terminal: npm run demo
  3. Open the demo in your browser (Expo starts it automatically) and type a non-ASCII value (e.g., 안녕하세요, こんにちは, or an emoji) into the input.
  4. Scan the QR code with a phone camera app. The decoded text should match exactly.

License

MIT