react-qr-code renders text as a QR image, whereas react-qr-reader and react-qr-scanner read camera frames. The two scanners expose different callbacks and host requirements; neither should be selected solely because an older README looks familiar.
react-qr-code takes a value and displays a QR code. Its web output is SVG, not an optional Canvas renderer. Size, foreground/background colors and error-correction level customize the symbol. The application supplies spacing around it. Its React Native route additionally needs react-native-svg. A displayed QR code and a camera decoder are complementary pieces of an application, not alternative implementations of the same step.
react-qr-reader exports QrReader and a related hook. Configure camera constraints and handle onResult's decoded result and error values. scanDelay controls the scanning interval, and styling props target the containing and video elements. The current latest package is a prerelease and declares React and React DOM peers in the React 16.8/17 families. Do not interpret its broad introductory wording as verified support for every later host. Its camera effect is established on mount, so prop changes should not be assumed to restart an existing session.
react-qr-scanner's current default component accepts constraints, onScan, onError, onLoad, resolution and qrArea. It creates a canvas during rendering and processes video frames through a worker. onScan receives a decoded result object with the current canvas, or null for a frame without a result. Adapt the result rather than treating it as a plain string. It declares React/React DOM 17 or 18 and is also a prerelease.
The scanner's packaged README describes older controls such as delay, facingMode and legacyMode. Those are not the scan controls implemented by the current exported component; a file-selection flow cannot be assumed from that text. Its ESM entry also imports runtime helpers not declared as production dependencies, so check module resolution in the consuming build.
A camera screen needs actual browser media support, camera availability and application handling for initialization, scan results and cleanup. Scanning no code in one frame differs from failing to initialize a camera. The application decides when to accept a result, pause or close the scanning view, and what to do with the decoded text.
Keep scanner components within the browser lifecycle. Switching scanner packages requires mapping props, callbacks and result objects; switching to the generator changes the entire task. None of these contracts justifies describing one scanner as a universal successor to the other.
Use it to display a supplied string as SVG. Provide surrounding whitespace and contrast; it neither opens a camera nor decodes an image.
Use its named QrReader component for a camera workflow with constraints, scanDelay and onResult. Its current latest is a prerelease with React/React DOM 16.8 or 17 peers.
Consider its browser-only camera component when React/React DOM 17 or 18 and its result-object contract fit. Its latest is a prerelease; use the actual constraints/resolution/qrArea interface rather than old legacyMode examples.
A
npm i react-qr-code
When using this library with React Native, you will also need to have react-native-svg installed.
npm i react-native-svg
cd ios && pod install
import React from "react";
import ReactDOM from "react-dom";
import QRCode from "react-qr-code";
ReactDOM.render(<QRCode value="hey" />, document.getElementById("Container"));
Note: If the QR code is likely to appear next to dark objects, you will need to wrap it in a light-colored container to preserve the 'quiet zone', e.g.
<div style={{ background: 'white', padding: '16px' }}>
<QRCode ... />
</div>
Responsive QR code example:
// Can be anything instead of `maxWidth` that limits the width.
<div style={{ height: "auto", margin: "0 auto", maxWidth: 64, width: "100%" }}>
<QRCode
size={256}
style={{ height: "auto", maxWidth: "100%", width: "100%" }}
value={value}
viewBox={`0 0 256 256`}
/>
</div>
| prop | type | default value | platform |
|---|---|---|---|
bgColor | string | '#FFFFFF' | web, ios, android |
fgColor | string | '#000000' | web, ios, android |
level | string ('L' 'M' 'Q' 'H') | 'L' | web, ios, android |
size | number | 256 | web, ios, android |
title | string | web | |
value | string | web, ios, android |
Adheres to the official QR spec and can store up to 2953 characters in value.
react-qr-code encodes data in UTF-8 byte mode to ensure non-ASCII text (e.g., Korean, Japanese, emoji) renders and scans correctly. Just pass a normal JavaScript string:
<QRCode value="한글 테스트 😊" />
No additional encoding is required on your side.
npm run demo-web-watchnpm run demo안녕하세요,
こんにちは, or an emoji) into the input.MIT