Gathering detailed insights and metrics for react-qr-barcode-scanner
Gathering detailed insights and metrics for react-qr-barcode-scanner
Gathering detailed insights and metrics for react-qr-barcode-scanner
Gathering detailed insights and metrics for react-qr-barcode-scanner
react-native-qrcode-scanner
A QR code scanner for React Native.
react-native-qr-barcode-scanner
Scan qr code, barcode
react-native-scanbot-barcode-scanner-sdk
Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS
react-native-vision-camera
A powerful, high-performance React Native Camera library.
A simple React Component using the client's webcam to read barcodes.
npm install react-qr-barcode-scanner
Typescript
Module System
Node Version
NPM Version
TypeScript (79.97%)
CSS (8.99%)
JavaScript (8.82%)
HTML (2.21%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
112 Stars
394 Commits
76 Forks
4 Watchers
2 Branches
7 Contributors
Updated on Jul 08, 2025
Latest Version
2.1.8
Package Id
react-qr-barcode-scanner@2.1.8
Unpacked Size
16.18 kB
Size
5.42 kB
File Count
8
NPM Version
10.8.2
Node Version
20.19.2
Published on
Jul 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
This is a simple React component built in Typescript to provide a webcam-based barcode scanner using react-webcam and @zxing/library. This component works on Computers and Mobile Devices (iOS 11 and above and Android Phones).
Thanks to the initial repo: https://github.com/dashboardphilippines/react-webcam-barcode-scanner
npm i react-qr-barcode-scanner
Try a demo of the scanner here.
1import { useState } from "react"; 2import BarcodeScanner from "react-qr-barcode-scanner"; 3 4function App() { 5 const [data, setData] = useState("Not Found"); 6 7 return ( 8 <> 9 <BarcodeScanner 10 width={500} 11 height={500} 12 onUpdate={(err, result) => { 13 if (result) setData(result.text); 14 else setData("Not Found"); 15 }} 16 /> 17 <p>{data}</p> 18 </> 19 ); 20} 21 22export default App;
1import dynamic from "next/dynamic" 2 3const BarcodeScanner = dynamic( 4 () => import("react-qr-barcode-scanner"), 5 { ssr: false } 6) 7 8// ... same as before
Type: function
, Required, Argument: error
, result
Function that returns the result for every captured frame. Text from barcode can be accessed from result.getText()
if there is a result.
Type: function
, Optional, Argument: error
If passed to the component, this function is called when there is an error with the camera (rather than with with reading the QR code, which would be passed to onUpdate
). An example would be an error thrown when the user does not allow the required camera permission. This can be handled with an onError
function similar to this:
1const onError = (error) => { 2 if (error.name === "NotAllowedError") { 3 // Handle messaging in our app after the user chooses to not allow the camera permissions 4 } 5};
Type: number
or string
, Optional, Default: 100%
Type: number
or string
, Optional, Default: 100%
Type: environment
or user
, Optional, Default: environment
user
is the user-facing (front) camera, and environment
is the rear camera.
Type: boolean
, Optional
Turn the camera flashlight on or off.
Torch will only work if the correct facingMode
is selected. For example, if "user" is selected but the flashlight corresponds to the "environment" camera, then it will not turn on.
Torch will not turn on if a static value of true
is passed. The initial value must be false
, and then switched to true
after a timeout or after a user action.
Here is an example using a timeout:
const [torchEnabled, setTorchEnabled] = useState<boolean>(false);
useEffect(() => {
setTimeout(() => {
setTorchEnabled(true);
}, 2000);
}, []);
<BarcodeScanner
torch={torchEnabled}
onUpdate={(err, result) => {}}
/>
Type: number
, Optional, Default: 500
Type: MediaTrackConstraints
, Optional
Type: boolean
, Optional
This prop is a workaround for a bug where the browser freezes if the webcam component is unmounted or removed. See known issues for more about this issue.
Type: BarcodeFormat[] | BarcodeStringFormat[]
, Optional
Array of barcode formats to decode. If not provided, all formats will be used. A smaller list may improve the speed of the scan.
These formats are supported by ZXing:
1D product | 1D industrial | 2D |
---|---|---|
UPC-A | Code 39 | QR Code |
UPC-E | Code 128 | Data Matrix |
EAN-8 | ITF | Aztec |
EAN-13 | RSS-14 | PDF 417 |
The camera can only be accessed over https or localhost
Browser compatibility is limited by react-webcam's usage of the Stream API: https://caniuse.com/stream. On iOS-Devices with iOS < 14.3 camera access works only in native Safari and not in other Browsers (Chrome, etc) or Apps that use an UIWebView or WKWebView. iOS 14.3 (released in December 2020) now supports WebRTC in 3rd party browsers as well.
There is a bug in the react-webcam
package that causes the browser to freeze when the component is unmounted or removed, or the camera video constraints are changed (for example, switching cameras or navigating away from the screen with the camera component). Please see this thread regarding the reported issue: https://github.com/mozmorris/react-webcam/issues/244. As a workaround, react-qr-barcode-scanner
allows passing a stopStream
prop to stop the video streams when true
is passed, allowing you to close the stream before unmounting the component or doing some other action that may cause the freeze. I found I needed to set a timeout to wait one tick before dismissing the modal in my use case to prevent the freeze. PRs to improve this issue are welcome!
Example:
1const [stopStream, setStopStream] = useState(false) 2//... 3const dismissQrReader = () => { 4 // Stop the QR Reader stream (fixes issue where the browser freezes when closing the modal) and then dismiss the modal one tick later 5 setStopStream(true) 6 setTimeout(() => closeModal(), 0) 7} 8//... 9<Modal> 10 <BarcodeScanner onUpdate={onUpdate} stopStream={stopStream} /> 11 <button onClick={dismissQrReader}> 12</Modal>
We welcome contributions to react-qr-barcode-scanner.
If you have an idea for a new feature or have discovered a bug, please open an issue.
Please yarn build
in the root and docs_src
directories before pushing changes.
Don't forget to add a title and a description explaining the issue you're trying to solve and your proposed solution.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
30 commit(s) and 9 issue activity found in the last 90 days -- score normalized to 10
Reason
SAST tool is run on all commits
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More