qrcode.react is a dedicated React component designed for generating QR codes, providing flexible rendering options through either SVG or Canvas. The package is actively maintained, with the current stable version being 4.2.0. It receives regular updates, as evidenced by recent additions like React v19 peer dependency support and new features such as `boostLevel` and the ability to encode multiple segments via an array `value` prop. A key differentiator is its extensive prop API, which allows for fine-grained control over QR code generation, including customization of size, error correction level, foreground/background colors, precise margins (`marginSize`), embedded images with opacity, and minimum QR code version. It ships with embedded TypeScript definitions, ensuring a robust development experience within modern React applications.
npm install qrcode.reactVerified import paths — ran on the pinned version, not inferred.
Demonstrates generating a QR code using `QRCodeSVG` with a variety of customization props, including error correction, colors, margins, and an embedded image, suitable for React 18+.
Upgrade React to version 16.8.0 or newer. Check `peerDependencies` for exact compatible ranges (currently `^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0`).
Replace `import QRCode from 'qrcode.react';` with `import { QRCodeSVG } from 'qrcode.react';` or `import { QRCodeCanvas } from 'qrcode.react';`.Replace `includeMargin={true}` with `marginSize={4}` (or any desired module count). If `includeMargin={false}` was used, simply omit `marginSize` or set it to `0`.Ensure that `null` is not passed to optional props; instead, omit the prop entirely if you want to use its default value, or pass `undefined`.
Upgrade to `qrcode.react@4.0.1` or newer to resolve type resolution problems with modern TypeScript configurations.
Ensure you are using named imports: `import { QRCodeSVG } from 'qrcode.react';` instead of `import QRCodeSVG from 'qrcode.react';`.Replace `includeMargin` with `marginSize`. For example, `includeMargin={true}` becomes `marginSize={4}`.Instead of passing `null` to an optional prop, omit the prop entirely, or pass `undefined` if you need to explicitly clear a previously set value.
If possible, switch to native ES module `import { QRCodeCanvas } from 'qrcode.react';`. If stuck with CommonJS, ensure your bundler supports dual-package exports, or try `const { QRCodeCanvas } = require('qrcode.react');`.