Skip to content
프로젝트

preflower/react-barcode-scanner

GitHub에서 보기

소개

A lightweight React scan library based on modern API

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original
logo

React Barcode Scanner

npm version npm version licence: MIT

Introduction

A lightweight barcode scanner based on the Barcode Detection API. It ships with an optional zbar.wasm polyfill and also works with compatible third-party implementations such as the ZXing WASM-based barcode-detector.

Usage

import { BarcodeScanner } from 'react-barcode-scanner'
import 'react-barcode-scanner/polyfill'

export default () => {
  return <BarcodeScanner />
}

The example uses the included ZBar WASM polyfill. You can select the compatible ZXing WASM-based barcode-detector from the installation guide when additional formats are required.

State scope and multiple scanners

Without a Provider, the scanner and state hooks use a shared compatibility scope, so existing single-scanner usage continues to work.

Use a separate BarcodeScannerProvider for each active scanner when controls or status live in other components:

import {
  BarcodeScanner,
  BarcodeScannerProvider,
  useStreamState,
  useTorch
} from 'react-barcode-scanner'

function ScannerControls () {
  const [stream] = useStreamState()
  const { isTorchSupported, isTorchOn, setIsTorchOn } = useTorch()

  return (
    <button
      disabled={!stream || !isTorchSupported}
      onClick={() => setIsTorchOn(!isTorchOn)}
    >
      Torch: {isTorchOn ? 'on' : 'off'}
    </button>
  )
}

export default function ScannerPanel () {
  return (
    <BarcodeScannerProvider>
      <BarcodeScanner />
      <ScannerControls />
    </BarcodeScannerProvider>
  )
}

See State Scope and Multiple Scanners for default values, lifecycle, torch operations and SSR guidance.

Detail

Documentation

License

MIT

관련 프로젝트 살펴보기

불러오는 중…