Skip to content
usefy

QRCode

ComponentsQR generation

QR code generator for React — hand-written ISO/IEC 18004 encoder, SVG/canvas/PNG output, module & eye shapes, gradients, logo embedding with scannability validation, zero dependencies

Live demo

Install

$ npm install @usefy/qr-code

Quick start

QRCode.tsx
import { QRCode } from "@usefy/qr-code";

function ShareLink() {
  return <QRCode value="https://usefy.dev" size={200} level="Q" title="Open usefy.dev" />;
}

API reference

<QRCode />

PropTypeDefaultDescription
valuestring | Uint8ArrayThe data to encode. Bytes are passed through verbatim, with no ECI header
sizenumber160Rendered width and height in px
render"svg" | "canvas""svg"SVG scales and server-renders; canvas is cheaper with many codes on screen
controllerRefRef<QRCodeController>Imperative handle for exports and downloads
titlestringAccessible name. Without one the code is aria-hidden
onError(error: Error) => voidCalled when encoding fails; the component renders nothing
throwOnErrorbooleanfalseThrow during render instead, for an error boundary
dprnumbermin(devicePixelRatio, 2)Backing-store scale for render="canvas"
className / styleForwarded to the root element

Plus every option in Options.

QRCodeController

MethodReturnsDescription
getMatrix()QRMatrix | nullThe encoded symbol
toSVG(options?)stringA standalone SVG document
toPNG(options?)Promise<{ dataURL, blob }>Rasterized PNG
download(format?, filename?)Promise<void>Triggers a browser download ("png" or "svg")

useQRCode(options)

const { matrix, error, svgProps, canvasRef, toSVG, toPNG, download } = useQRCode({
  value: "https://usefy.dev",
  level: "Q",
});
FieldTypeDescription
matrixQRMatrix | nullThe encoded symbol, null when encoding failed
errorError | nullThe encoding failure. Never thrown by the hook
svgPropsQRSVGProps | nullStructured SVG data for rendering as JSX
canvasRef(el: HTMLCanvasElement | null) => voidAttach to a <canvas> to have it drawn and kept in sync
toSVG / toPNG / downloadAs on the controller

Go deeper

This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.

More in components