Utilities
QRCode
Scannable QR codes (ISO/IEC 18004) as crisp SVG: UTF-8 text, versions 1–40, four error-correction levels, no dependencies.
import { QRCode, encodeQR } from '@reactloom/ui';Examples
Link with a text alternative
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.
L · 7% recoverable
M · 15% (default)
Q · 25%
H · 30%, for print and logos
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
- Network
- Office Guest
- Password
- welcome-2031
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
| Prop | Type | Default |
|---|---|---|
valuerequiredText or URL, encoded as UTF-8 bytes. | string | — |
labelAccessible name; say where the code leads. | string | 'QR code: {value}' |
levelError correction: 7%, 15%, 25% or 30% of the code can be damaged. | 'L' | 'M' | 'Q' | 'H' | 'M' |
sizeWidth and height in pixels. | number | 160 |
quietZoneLight margin in modules; the standard asks for 4. | number | 4 |
fgColorDark modules. Keep them dark on a light background. | string | '#000000' |
bgColorBackground and quiet zone. | string | '#ffffff' |
tooLongMessageText 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 bylabel. 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.