Create QR Code Generator in NextJS (Server Components + App Router + PNG Download)
Learn how to build a fast and SEO-friendly QR Code Generator in NextJS using Server Components and Client Components. Includes live preview, color customization, dynamic sizing, and PNG download.
QR codes are widely used in modern applications for payments, authentication, sharing links, WiFi access, event tickets, product packaging, and marketing campaigns. In this tutorial, you will build a complete QR Code Generator using NextJS App Router architecture. The tool will allow users to enter any text or URL, customize QR size and colors, preview changes instantly, and download the generated QR code as a PNG image.
Unlike traditional React applications, NextJS enables hybrid rendering with Server Components and Client Components. This improves performance, reduces JavaScript bundle size, and enhances SEO — making it ideal for tool websites and utility platforms.
What You Will Build
- Instant QR code generation while typing
- Foreground and background color customization
- Adjustable QR size input
- One-click PNG download feature
- Modern architecture using Server and Client Components
- SEO-friendly tool page structure
- Optimized rendering for faster page load
Prerequisites
- Basic knowledge of React or NextJS
- Node.js installed on your system
- Understanding of functional components and hooks
- Basic knowledge of SVG and Canvas is helpful but optional
Step 1: Create a New NextJS App
Create a new NextJS project using the official CLI. Make sure to select App Router during setup.
After running the development server, open http://localhost:3000 to verify your application is working.
Step 2: Install QR Code Library
Install a lightweight library that generates QR codes as SVG.
- react-qr-code converts text or URLs into QR SVG instantly
- SVG output makes it easy to export to PNG or download as vector
Step 3: Project Folder Structure
Keeping UI logic inside reusable components helps maintain scalability when building multiple QR tools.
Step 4: Build QRGenerator Client Component
Since the generator requires browser APIs like Canvas, Image, and event handlers, it must be implemented as a Client Component.
Step 5: Render Client Component inside Server Page
NextJS pages are Server Components by default. Import your generator component inside the page.
Understanding Server vs Client Components
Server Components render on the server and send HTML to the browser. This reduces JavaScript bundle size and improves page performance. Client Components handle interactivity such as form input, state management, animations, and browser APIs.
- Use Server Components for layout, SEO content, and data fetching
- Use Client Components for interactive tools
- This separation improves maintainability and performance
How PNG Export Works
The QR code library generates SVG markup. The browser serializes this SVG using XMLSerializer. Then an Image object loads the encoded SVG. Canvas draws the image and exports PNG data using toDataURL. Finally, a temporary anchor element triggers the file download.
Real World Use Cases
- Website link sharing
- UPI and payment QR codes
- WiFi access QR
- Digital business cards
- Product packaging and logistics
- Event tickets and check-ins
Performance and SEO Advantages
- Server rendered HTML improves crawlability
- Less hydration cost on initial load
- Better Core Web Vitals
- Faster First Contentful Paint
- Improved ranking potential for tool pages
Advanced Improvements
- Allow SVG download option
- Embed logo inside QR
- Save last settings in localStorage
- Add URL validation
- Create presets for WhatsApp, Email, WiFi
- Add error correction level control
- Generate high resolution print-ready PNG
- Create shareable QR links
Ready to create your free QR code?
No sign-up required. Generate, customise, and download in seconds.
Create QR Code FreeMore Articles
View allStatic vs Dynamic QR Codes: Which Should You Use?
Static QR codes are free and never expire. Dynamic codes are trackable and editable. Here's exactly …
ReadUnlocking Convenience: How to Use a QR Code Generator
Discover the power of QR code generators and learn how to create, customize, and deploy QR codes eff…
ReadCreate QR Code using Reactjs (TypeScript + Download PNG)
Build a complete QR code generator in React with live preview, color customization, size controls, a…
Read