1.1.7 • Published 4 years ago

react-qrcode-scan v1.1.7

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

react-qrcode-scan

React componnent write by typescript for scan qrcode. Base on instascan.js

Usage

yarn add react-qrcode-scan
// or
npm install react-qrcode-scan --save
import { QRScaner, Camera } from "react-qrcode-scan";

export default class QRReader extends React.Component<RenderProps, RenderState> {
    ...
    render() {
        const { results, camera } = this.state;
        return (
            <Camera onError={this.onError}>
                { cameras => cameras.length > 0 ?
                    <QRScaner onStart={this.onStart} onScan={this.onScan} camera={cameras[0]} onError={this.onError} />
                    : <div> No Camera</div>}
            </Camera>
        );
    }
}

You can get full example code Here
Or See Live example

API

react-qrcode-scan exports two component:

<Camera />

<Camera/> will fetch for the available cameras on your device, and return the camera device list;

<QRScaner/>

Scanner Properties

nametyperequireddescription
cameraobjecttrueCamera object returned by \<Camera \/>
onError(err:Error) => volidtrueEmitted when scan got error
onScan(content:string) => volidtrueEmitted when a QR code is scanned using the camera in continuous mode
stopbooleanfalseIf stop is true the camera stops and vice-versa
onStart(camera) => volidfalseCalled when camera is active and scanning has started
onStop() => volidfalseCalled when camera and scanning have stopped
onActivefunctionfalseEmitted when the scanner becomes active as the result of stop becoming false or the tab gaining focus
onInactive() => volidfalseEmitted when the scanner becomes inactive as the result of stop becoming true or the tab losing focus
classNamestringfalseclassname, will be used for descript video tag
optionsobjectfalseSame options from Instascan.Scanner
styleReact.cssPropertyfalseinline styles, will be pass to video tag
videoAttrReact.VideoHTMLAttributesfalsevideo tag attribute

For more details check the Instascan API

How to run example
$ git clone repo
$ yarn run start
$ open http://localhost:8898