The required package qrcode.react has already been added to package.json. Just run:
npm install'use client';
import { useState } from 'react';
import { Share2 } from 'lucide-react';
import { ShareModal } from '@/components';
export function PostHeader({ postId, title }) {
const [showShare, setShowShare] = useState(false);
return (
<>
<div className="flex justify-between items-center">
<h1>{title}</h1>
<button
onClick={() => setShowShare(true)}
className="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg"
>
<Share2 size={18} />
Share
</button>
</div>
<ShareModal
isOpen={showShare}
onClose={() => setShowShare(false)}
shareUrl={`https://teachlink.com/post/${postId}`}
title="Share this post"
/>
</>
);
}import { QRCodeComponent } from '@/components';
export function TopicCard({ topicSlug }) {
return (
<div className="border rounded-lg p-4">
<h2>Share via QR</h2>
<QRCodeComponent value={`https://teachlink.com/topics/${topicSlug}`} size={200} />
</div>
);
}export function ProfileCard({ username }) {
const [showShare, setShowShare] = useState(false);
return (
<>
<button onClick={() => setShowShare(true)}>Share Profile</button>
<ShareModal
isOpen={showShare}
onClose={() => setShowShare(false)}
shareUrl={`https://teachlink.com/profile/${username}`}
title={`Share ${username}'s Profile`}
fgColor="#3b82f6"
/>
</>
);
}export function ResourceCard({ resourceId, title }) {
return (
<div className="card">
<h3>{title}</h3>
<QRCodeComponent value={`https://teachlink.com/resource/${resourceId}`} size={150} />
<p className="text-xs text-gray-500 mt-2">Scan to access</p>
</div>
);
}export function SharePage({ item }) {
const [showShare, setShowShare] = useState(false);
return (
<div className="page-layout">
<header>
<h1>{item.title}</h1>
<button onClick={() => setShowShare(true)}>Share</button>
</header>
<ShareModal
isOpen={showShare}
onClose={() => setShowShare(false)}
shareUrl={`${process.env.NEXT_PUBLIC_DOMAIN}/${item.type}/${item.id}`}
title={`Share ${item.type}`}
description={`Share this ${item.type} with others`}
qrSize={300}
/>
</div>
);
}<ShareModal
shareUrl={url}
title="Share"
fgColor="#dc2626" // Red QR code
bgColor="#fef2f2" // Light red background
/>// Mobile
<QRCodeComponent value={url} size={128} />
// Desktop
<QRCodeComponent value={url} size={384} />// Dark mode
<QRCodeComponent
value={url}
fgColor="#ffffff" // White modules
bgColor="#1f2937" // Dark background
/>
// Brand color
<QRCodeComponent
value={url}
fgColor="#3b82f6" // Blue modules
bgColor="#f0f9ff" // Light blue background
/>- Post/article sharing
- Profile links
- Topic pages
- Resource downloads
- Event registration
- Classroom resources
- External links
- Mobile deeplinks
- Private/sensitive content
- Authentication tokens
- Large data payloads (QR codes have limits)
- Real-time changing content (use API endpoints)
// Your custom URL scheme
const shareUrl = `teachlink://post/${postId}?utm_source=qr&utm_medium=share`;
<ShareModal isOpen={showShare} onClose={() => setShowShare(false)} shareUrl={shareUrl} />;export function ShareButton({ isLoggedIn, itemId }) {
const [showShare, setShowShare] = useState(false);
if (!isLoggedIn) {
return <button disabled>Login to share</button>;
}
return (
<>
<button onClick={() => setShowShare(true)}>Share</button>
<ShareModal
isOpen={showShare}
onClose={() => setShowShare(false)}
shareUrl={`https://teachlink.com/post/${itemId}`}
/>
</>
);
}import { ErrorBoundarySystem } from '@/components';
export function SafeShare({ itemId }) {
return (
<ErrorBoundarySystem>
<ShareModal
isOpen={true}
onClose={() => {}}
shareUrl={`https://teachlink.com/post/${itemId}`}
/>
</ErrorBoundarySystem>
);
}http://localhost:3000/qr-code-demo
- Open
/qr-code-demo - Modify the URL input
- Use the QR preview
- Test download, print, and copy
- Use browser DevTools mobile view
- Or access demo on actual mobile device
- Scan QR with phone camera
- Share functionality works on mobile
- Import
ShareModalorQRCodeComponent - Add
'use client'directive if on server component - Use
useStateto manage modal visibility - Provide
shareUrlwith full domain - Test in light and dark modes
- Test on mobile viewport
- Verify URL accessibility
- Add loading/error states if needed
- Customize colors if brand-specific
// ❌ Wrong
<QRCodeComponent value="" />
// ✅ Correct
<QRCodeComponent value="https://example.com" />- Check browser is HTTPS (or localhost)
- Test in a different browser
- Check browser permissions
- Verify Tailwind CSS is loaded
- Check dark mode context is available
- Inspect Modal parent styling
- Check browser popup blocking
- Try a different file format
- Browser might not support canvas download
- Demo Page: Visit
/qr-code-demofor live examples - Documentation: See QR_CODE_FEATURE.md
- API Reference: Check component JSDoc comments
- Tests: See
src/utils/__tests__/generate-qr.test.ts
Happy Coding! 🚀
Start by copying one of the patterns above and customize it for your use case.