Examples

Link with a text alternative

Preview
Example.tsx
import { Link, QRCode, Stack } from '@reactloom/ui';

// Name the code by where it leads, and give the same link as text for people who cannot scan.
export default function BasicQRCode() {
  return (
    <Stack gap="2" align="start">
      <QRCode value="https://reactloom.dev/docs" label="QR code: ReactLoom documentation" size={148} />
      <Link href="https://reactloom.dev/docs">reactloom.dev/docs</Link>
    </Stack>
  );
}

Error-correction levels

Higher levels survive more damage or a logo on top, at the cost of a denser code.

Preview

L · 7% recoverable

M · 15% (default)

Q · 25%

H · 30%, for print and logos

Example.tsx
import { HStack, QRCode, Stack, Text } from '@reactloom/ui';

const levels = [
  { level: 'L', note: '7% recoverable' },
  { level: 'M', note: '15% (default)' },
  { level: 'Q', note: '25%' },
  { level: 'H', note: '30%, for print and logos' },
] as const;

// Higher error correction survives more damage but needs a denser code for the same text.
export default function Levels() {
  return (
    <HStack gap="4" wrap>
      {levels.map(({ level, note }) => (
        <Stack key={level} gap="1" align="center">
          <QRCode value="https://reactloom.dev/components/qr-code" level={level} size={120} label={`QR code with error correction ${level}`} />
          <Text size="sm">
            {level} · {note}
          </Text>
        </Stack>
      ))}
    </HStack>
  );
}

Wi-Fi sign-in

Preview
Network
Office Guest
Password
welcome-2031
Example.tsx
import { DescriptionItem, DescriptionList, HStack, QRCode } from '@reactloom/ui';

// Phones offer to join the network when they scan a WIFI: payload. Show the details as text too.
export default function WifiQRCode() {
  return (
    <HStack gap="4" align="center" wrap>
      <QRCode value="WIFI:T:WPA;S:Office Guest;P:welcome-2031;;" label="QR code: join the Office Guest Wi-Fi network" size={140} />
      <DescriptionList>
        <DescriptionItem term="Network">Office Guest</DescriptionItem>
        <DescriptionItem term="Password">welcome-2031</DescriptionItem>
      </DescriptionList>
    </HStack>
  );
}

API reference

QRCode props
PropTypeDefault
valuerequired
Text or URL, encoded as UTF-8 bytes.
string—
label
Accessible name; say where the code leads.
string'QR code: {value}'
level
Error correction: 7%, 15%, 25% or 30% of the code can be damaged.
'L' | 'M' | 'Q' | 'H''M'
size
Width and height in pixels.
number160
quietZone
Light margin in modules; the standard asks for 4.
number4
fgColor
Dark modules. Keep them dark on a light background.
string'#000000'
bgColor
Background and quiet zone.
string'#ffffff'
tooLongMessage
Text shown when the value is too long for any QR code (2,331 bytes at level M).
string—

encodeQR(text, { level, minVersion, maxVersion, mask }) returns the module matrix for drawing on a canvas, in a PDF or on a label printer.

Accessibility

  • The code is an image (role="img") named by label. Describe the destination, not the encoding.
  • Always put the link or information next to the code: not everyone can scan.
  • When the text is too long, a visible message replaces the code instead of an unreadable image.

Usage guidelines

Do

  • Keep dark modules on a light background and keep the quiet zone.
  • Use level H when the code is printed small or partly covered.
  • Test with the phones your users have.

Don’t

  • Don’t invert the colours for dark mode: many scanners cannot read light-on-dark codes.
  • Don’t encode long text; link to it instead.