A react component for reading QR codes from the webcam.
npm install react-qr-reader-es6
facingMode will not affect it.
npm install --save react-qr-reader-es6
js
import React, { Component } from 'react'
import QrReader from 'react-qr-reader'
class Test extends Component {
state = {
result: 'No result'
}
handleScan = data => {
if (data) {
this.setState({
result: data
})
}
}
handleError = err => {
console.error(err)
}
render() {
return (
delay={300}
onError={this.handleError}
onScan={this.handleScan}
style={{ width: '100%' }}
/>
{this.state.result}
)
}
}
`
Props
$3
| Prop | Argument | Description |
| ----------- | ---------------- | --------------------------------------------------------------------------------------------------------------- |
| onScan | result | Scan event handler. Called every scan with the decoded value or null if no QR code was found. |
| onError | Error | Called when an error occurs. |
| onLoad | object | Called when the component is ready for use. Object properties are mirrorVideo: boolean, streamLabel: string |
| onImageLoad | img onLoad event | Called when the image in legacyMode is loaded. |
$3
| Prop | Type | Default | Description |
| -------------- | ----------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| delay | number or false | 500 | The delay between scans in milliseconds. To disable the interval pass in false. |
| facingMode | user or environment | environment | Specify which camera should be used (if available). |
| resolution | number | 600 | The resolution of the video (or image in legacyMode). Larger resolution will increase the accuracy but it will also slow down the processing time. |
| style | a valid React style | none | Styling for the container element. Warning The preview will always keep its 1:1 aspect ratio. |
| className | string | none | ClassName for the container element. |
| showViewFinder | boolean | true | Show or hide the build in view finder. See demo |
| constraints | object | null | Use custom camera constraints that the override default behavior. MediaTrackConstraints |
| legacyMode | boolean | false | If the device does not allow camera access (e.g. IOS Browsers, Safari) you can enable legacyMode to allow the user to take a picture (On a mobile device) or use an existing one. To trigger the image dialog just call the method openImageDialog from the parent component. Warning You must call the method from a user action (eg. click event on some element). |
Dev
$3
npm install
$3
npm run build
$3
npm run storybook
$3
npm run lint`