qrcode.react - React QR Code Component

4.2.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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+.

import ReactDOM from 'react-dom/client';
import React from 'react';
import { QRCodeSVG } from 'qrcode.react';

const App = () => (
  <div style={{ padding: '20px', backgroundColor: '#f0f0f0', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
    <h1>Visit React Documentation</h1>
    <p>Scan the QR code below to navigate to the official React documentation website.</p>
    <QRCodeSVG
      value="https://react.dev/"
      size={256}
      level="H" /* High error correction */
      bgColor="#ffffff"
      fgColor="#20232a"
      marginSize={6}
      imageSettings={{
        src: "https://react.dev/favicon.ico",
        x: undefined,
        y: undefined,
        height: 30,
        width: 30,
        excavate: true,
        opacity: 0.9
      }}
      title="React Documentation QR Code"
      minVersion={4}
      boostLevel={false}
    />
    <p style={{ marginTop: '20px', maxWidth: '400px', textAlign: 'center' }}>
      This example demonstrates generating an SVG QR code with various customizations:
      setting a specific value, size, error correction level (High), custom colors,
      a larger margin, and embedding the React favicon with partial opacity.
    </p>
  </div>
);

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(<App />);

view raw JSON →