@blackbox-vision/react-qr-reader

中文文档
5.0.0发布于 2021/08/05MITTypeScriptESM + CJS近 30 天下载 4382

A React Component for reading QR codes from the webcam

原始使用文档
文档目录12 节
  1. Table of contents
  2. Use Case
  3. Compatibility
  4. Installation
  5. NPM
  6. YARN
  7. Example Usage
  8. Component API
  9. Browser Support
  10. Issues
  11. Contributing
  12. License

Lib logo

React QR Reader npm version License: MIT Known Vulnerabilities

:rocket: React QR Reader component. Check out the demo.

Table of contents

Use Case

You need a component for Scanning QR codes from a web browser based app.

Compatibility

This component has been tested in the following browsers:

  • Chrome Mac OS & Android
  • Firefox Mac OS & Android
  • Safari Mac OS & IOS

Since this library does internal use of hooks you need React >= 16.8.0.

Installation

You can install this library via NPM or YARN.

NPM

npm i @blackbox-vision/react-qr-reader

YARN

yarn add @blackbox-vision/react-qr-reader

Example Usage

After reading and performing the previous steps, you should be able to import the library and use it like in this example:

import React, { useState } from 'react';
import { QrReader } from '@blackbox-vision/react-qr-reader';

const Test = (props) => {
  const [data, setData] = useState('No result');

  return (
    <>
      <QrReader
        onResult={(result, error) => {
          if (!!result) {
            setData(result?.text);
          }

          if (!!error) {
            console.info(error);
          }
        }}
        style={{ width: '100%' }}
      />
      <p>{data}</p>
    </>
  );
};

Component API

The QrReader component has the following props:

PropertiesTypesDefault ValueDescription
constraintsMediaTrackConstraints{ facingMode: 'user' }Specify which camera should be used (if available).
onResultfunctionnoneScan event handler
videoIdstringvideoThe ID for the video element
scanDelaynumber500The scan period for the QR hook
ViewFindercomponentnoneViewFinder component to rendering over the video element
classNamestringnoneClassName for the container element.
containerStyleobjectnoneStyle object for the container element.
videoContainerStyleobjectnoneStyle object for the video container element.
videoStyleobjectnoneStyle object for the video element.

Browser Support

If you need to support older browsers, checkout this guide in how to make it compatible with legacy ones

Issues

Please, open an issue following one of the issues templates. We will do our best to fix them.

Contributing

If you want to contribute to this project see contributing for more information.

License

Distributed under the MIT license. See LICENSE for more information.

版本与发布记录

@blackbox-vision/react-qr-reader 共发布 31 个版本,首次发布于 2020/03/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2021/08/055 年前
4.1.12021/08/025 年前
4.1.02021/07/135 年前
4.0.12021/06/235 年前
4.0.02021/06/235 年前
3.1.02021/06/235 年前

关于 @blackbox-vision/react-qr-reader 的常见问题

@blackbox-vision/react-qr-reader 是什么?

A React Component for reading QR codes from the webcam

如何安装 @blackbox-vision/react-qr-reader?

在项目目录运行 npm install @blackbox-vision/react-qr-reader,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.8.0 || ^17.0.0)、react-dom(^16.8.0 || ^17.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@blackbox-vision/react-qr-reader 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@blackbox-vision/react-qr-reader 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@blackbox-vision/react-qr-reader 可以商用吗?

@blackbox-vision/react-qr-reader 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@blackbox-vision/react-qr-reader 的下载量有多少?

根据 npm 官方下载统计,@blackbox-vision/react-qr-reader 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,382 次,日均约 146 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@blackbox-vision/react-qr-reader 还在维护吗?

最新版本 5.0.0 发布于 2021/08/05(5 年前);至今共发布 31 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/03/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。