import { useEffect, useState } from 'react'; import { Sheet, CodeLabel } from './ui'; /** QR is generated lazily so the library is not in the first-page bundle. */ export function QrModal({ url, code, onClose }: { url: string; code: string; onClose: () => void }) { const [cells, setCells] = useState<{ n: number; path: string } | null>(null); useEffect(() => { let alive = true; import('qrcode-generator').then(({ default: qrcode }) => { const qr = qrcode(0, 'M'); qr.addData(url); qr.make(); const n = qr.getModuleCount(); let path = ''; for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) if (qr.isDark(y, x)) path += `M${x} ${y}h1v1h-1z`; if (alive) setCells({ n, path }); }); return () => { alive = false; }; }, [url]); return (

휴대폰 카메라로 찍으면 들어와요

{cells ? ( ) : (

만드는 중…

)}

코드

); }