Skip to content

Repository files navigation

@devmehq/react-qr-code

🎯 Simple & Advanced React component to generate QR codes with custom styling, multiple render formats, and image embedding support.

NPM versionBuild StatusDownloadsBundle SizeLicenseUNPKG

Edit react-qr-code-demo

✨ Features

  • 🎨 Customizable: Colors, sizes, margins, and styles
  • 🖼️ Multiple Formats: Render as SVG or Canvas
  • 📱 Responsive: Scales perfectly on all devices
  • 🏞️ Image Embedding: Add logos or images to QR codes
  • 🛡️ Error Correction: Four levels (L, M, Q, H)
  • 📦 Lightweight: Zero dependencies, small bundle size
  • 🔧 TypeScript: Full TypeScript support
  • Performance: Optimized rendering with React hooks

📦 Installation

# Using npm
npm install @devmehq/react-qr-code
# Using yarn
yarn add @devmehq/react-qr-code
# Using pnpm
pnpm add @devmehq/react-qr-code

🚀 Quick Start

Basic Usage

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'functionApp(){return<ReactQrCodevalue="https://github.com/devmehq/react-qr-code"/>}

With Custom Styling

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'functionStyledQRCode(){return(<ReactQrCodevalue="https://your-website.com"size={300}bgColor="#f3f4f6"fgColor="#1f2937"level="H"marginSize={4}style={{borderRadius: '8px'}}className="shadow-lg"/>)}

Canvas Rendering

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'functionCanvasQRCode(){return(<ReactQrCodevalue="https://your-website.com"renderAs="canvas"size={256}/>)}

With Logo/Image

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'functionQRCodeWithLogo(){return(<ReactQrCodevalue="https://your-website.com"size={256}images={[{src: '/logo.png',height: 50,width: 50,excavate: true,},]}/>)}

📖 API Reference

ReactQrCode Props

PropTypeDefaultDescription
valuestringRequiredThe value to encode in the QR code
renderAs'svg' | 'canvas''svg'Render format (SVG or Canvas)
sizenumber256Size of the QR code in pixels
bgColorstring'#ffffff'Background color (CSS color value)
fgColorstring'#000000'Foreground color (CSS color value)
level'L' | 'M' | 'Q' | 'H''L'Error correction level
marginSizenumber0Margin around the QR code in pixels
styleCSSPropertiesundefinedReact style object
classNamestringundefinedCSS class name
titlestringundefinedTitle for SVG accessibility
idstringundefinedHTML id attribute
imagesReactQrCodeImageProps[]undefinedArray of images to embed in the QR code

ReactQrCodeImageProps

PropertyTypeDefaultDescription
srcstringRequiredImage source URL
xnumberAuto-centeredX position of the image
ynumberAuto-centeredY position of the image
heightnumber10% of QR sizeHeight of the image
widthnumber10% of QR sizeWidth of the image
excavatebooleanfalseWhether to clear QR modules behind the image

Error Correction Levels

LevelError CorrectionData Capacity
L~7%High
M~15%Medium
Q~25%Medium-Low
H~30%Low

🎨 Styling & Customization

Responsive Design

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'functionResponsiveQRCode(){return(<divstyle={{width: '100%',maxWidth: '400px'}}><ReactQrCodevalue="https://your-website.com"size={256}style={{width: '100%',height: 'auto'}}/></div>)}

Dark Mode Support

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'functionDarkModeQRCode({ isDarkMode }){return(<ReactQrCodevalue="https://your-website.com"bgColor={isDarkMode ? '#1f2937' : '#ffffff'}fgColor={isDarkMode ? '#f3f4f6' : '#000000'}/>)}

Custom CSS Classes

importReactfrom'react'import{ReactQrCode}from'@devmehq/react-qr-code'import'./styles.css'functionCustomStyledQRCode(){return(<ReactQrCodevalue="https://your-website.com"className="qr-code-custom"size={300}/>)}
/* styles.css */
.qr-code-custom {
border-radius:16px;
box-shadow:04px6pxrgba(0,0,0,0.1);
padding:16px;
background:linear-gradient(135deg,#667eea0%,#764ba2100%);
}

Note: When using renderAs="canvas" on high-density displays, the canvas is scaled for pixel-perfect rendering. Custom styles are merged with internal scaling styles.

💡 Use Cases

WiFi Password Sharing

functionWiFiQRCode({ ssid, password, security ='WPA'}){constwifiString=`WIFI:T:${security};S:${ssid};P:${password};;`return<ReactQrCodevalue={wifiString}size={256}level="H"/>}

Contact Information (vCard)

functionContactQRCode({ name, phone, email }){constvCard=`BEGIN:VCARDVERSION:3.0FN:${name}TEL:${phone}EMAIL:${email}END:VCARD`return<ReactQrCodevalue={vCard}size={256}level="M"/>}

Two-Factor Authentication

functionTwoFactorQRCode({ secret, issuer, accountName }){constotpauth=`otpauth://totp/${issuer}:${accountName}?secret=${secret}&issuer=${issuer}`return(<ReactQrCodevalue={otpauth}size={256}level="H"images={[{src: '/logo.png',height: 40,width: 40,excavate: true,},]}/>)}

Payment Links

functionPaymentQRCode({ amount, recipient, currency ='USD'}){constpaymentLink=`https://pay.example.com/?to=${recipient}&amount=${amount}&currency=${currency}`return<ReactQrCodevalue={paymentLink}size={300}level="H"marginSize={4}/>}

qrcode-demo

🧪 Testing

# Run tests
yarn test# Run tests in watch mode
yarn test:watch
# Generate coverage report
yarn test:coverage

🔧 Development

# Install dependencies
yarn install
# Build the library
yarn build
# Run linting
yarn lint-js
# Format code
yarn prettier

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 Roadmap

  • Download QR code as image (PNG/JPEG/SVG)
  • Share QR code functionality
  • Server-side rendering (SSR) support
  • Corner dot customization
  • Gradient color support
  • Custom shape modules (dots, rounded, etc.)
  • Animation support
  • Batch QR code generation
  • QR code scanner component

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • QR Code is a registered trademark of DENSO WAVE INCORPORATED
  • Built with ❤️ by the DEV.ME team
  • Inspired by the QR code specification and community feedback

📧 Support

For support, email support@dev.me or open an issue on GitHub.


Made with ❤️ by DEV.ME

About

A QRCode React Component ( SVG / Canvas )

Topics

Resources

Contributing

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages