Build faster with Premium Chakra UI Components 💎

Learn more
Skip to Content
DocsPlaygroundGuidesBlog
Sponsor

QR Code

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

SourceStorybookRecipeArk

Setup

If you don't already have the snippet, run the following command to add the qr-code snippet

npx @chakra-ui/cli snippet add qr-code

The snippet includes a closed component composition for the QR Code component.

Usage

Learn how to use the QR Code component in your project. Let's take a look at the most basic example:

import { QrCode } from "@/components/ui/qr-code"
<QrCode value="..." />

Examples

Sizes

Use the size prop to set the size of the QR code.

Logo Overlay

Pass the children prop to the QrCode.Overlay component to add a logo or overlay to the QR code.

Fill

Use the fill prop to set the fill color of the QR code.

Download

Use the QrCode.DownloadTrigger to download the QR code.

The fileName and the mimeType props are required.

Error Correction

In cases where the link is too long or the logo overlay covers a significant area, the error correction level can be increased.

Use the encoding.ecc or encoding.boostEcc property to set the error correction level:

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

Store

The RootProvider component provides a context for the QR code.

It accepts the value of the useQrCode hook. You can leverage it to access the component state and methods from outside the QR code.

Input

Here's an example of how to use the QrCode component with an Input component.

Spinner

Here's an example of how to use the QrCode component with a Spinner component.

Without Snippet

Here's how to setup the QR code without using the snippet.

Props

Root

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
defaultValue
string

The initial value of the qr code when it is first rendered. Use when you do not need to control the state of the qr code.

encoding
QrCodeGenerateOptions

The qr code encoding options.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string; frame: string }>

The element ids.

onValueChange
(details: ValueChangeDetails) => void

Callback fired when the value changes.

value
string

The value to encode.

DownloadTrigger

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

For more details, read our Composition guide.
quality
number

The quality of the image.

Previous

Progress

Next

Radio Card