preflower/react-barcode-scanner
关于
A lightweight React scan library based on modern API
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文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
License
MIT
探索相关项目
加载中…