QR Code

A component that generates a QR code based on the provided data.

Loading...

Anatomy

<QrCode.Root>
  <QrCode.Frame>
    <QrCode.Pattern />
  </QrCode.Frame>
  <QrCode.Overlay />
  <QrCode.DownloadTrigger />
</QrCode.Root>

Examples

With Overlay

Add a logo or overlay to brand the QR code.

Error Correction

Raise the error correction level when the link is long or the overlay covers much of the code. Set it with encoding.ecc or encoding.boostEcc:

  • L: recovers up to 7% data loss (default)
  • M: up to 15%
  • Q: up to 25%
  • H: up to 30%

Root Provider

Use RootProvider with the useQrCode hook to access the state and methods from outside the component.

Download

QrCode.DownloadTrigger downloads the QR code as an image. Set fileName and mimeType for the file.

API Reference

Props

Root

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
defaultValue
string

The initial value to encode when rendered. Use when you don't need to control the value of the qr code.

encoding
QrCodeGenerateOptions

The qr code encoding options.

id
string

The unique identifier of the machine.

ids
ElementIds

The element ids.

onValueChange
(details: ValueChangeDetails) => void

Callback fired when the value changes.

pixelSize
number

The pixel size of the qr code.

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

value
string

The controlled value to encode.

CSS VariableDescription
--qrcode-pixel-sizeThe size of the Root
--qrcode-widthThe width of the Root
--qrcode-heightThe height of the Root

DownloadTrigger

Defines the <button> element.

AttributeDefaultType
fileName
string

The name of the file.

mimeType
DataUrlType

The mime type of the image.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
quality
number

The quality of the image.

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Frame

Defines the <svg> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Overlay

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Pattern

Defines the <path> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

RootProvider

Defines the <div> element.

AttributeDefaultType
value
UseQrCodeReturn

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Context

API

PropertyType
value
string

The value to encode.

setValue
(value: string) => void

Set the value to encode.

getDataUrl
(type: DataUrlType, quality?: number) => Promise<string>

Returns the data URL of the qr code. Includes the overlay when present.