'use client' import { useState, useRef } from 'react' import QRCode from 'qrcode' export default function QRGenerator() { const [text, setText] = useState('') const [qrDataUrl, setQrDataUrl] = useState('') const [size, setSize] = useState(300) const [darkColor, setDarkColor] = useState('#000000') const [lightColor, setLightColor] = useState('#FFFFFF') const canvasRef = useRef(null) const generateQR = async () => { if (!text) return try { const canvas = canvasRef.current if (!canvas) return await QRCode.toCanvas(canvas, text, { width: size, margin: 2, color: { dark: darkColor, light: lightColor } }) setQrDataUrl(canvas.toDataURL('image/png')) } catch (err) { console.error('Error generating QR code:', err) } } const downloadQR = () => { if (!qrDataUrl) return const link = document.createElement('a') link.download = 'qrcode.png' link.href = qrDataUrl document.body.appendChild(link) link.click() document.body.removeChild(link) } return (

QR Code Generator

Generate QR codes for text, URLs, or any other content. Customize the size and colors, then download the QR code as a PNG image.

setText(e.target.value)} placeholder="Enter text or URL" className="w-full bg-zinc-700 text-white rounded-md border border-gray-600 p-2" />
setSize(Number(e.target.value))} className="w-full" />
setDarkColor(e.target.value)} className="w-full h-10 rounded-md cursor-pointer bg-zinc-700 p-1" />
setLightColor(e.target.value)} className="w-full h-10 rounded-md cursor-pointer bg-zinc-700 p-1" />
{qrDataUrl && (
Generated QR Code
)}
) }