Back to Blog
January 5, 20269 min readTechnical Deep Dive:

Technical Deep Dive: Using Next.js 15 and UI Components from Replay for Scaling

R
Replay Team
Developer Advocates

TL;DR: This article provides a technical deep dive into leveraging Next.js 15 and UI components generated by Replay to build scalable web applications, focusing on behavior-driven reconstruction and seamless integration.

Next.js 15 is here, and it's a game-changer for building performant and scalable web applications. But what if you could accelerate your development process even further by automatically generating UI components directly from user behavior? That's where Replay comes in. Replay analyzes video recordings of user interactions to reconstruct working UI components, saving you countless hours of manual coding. This article explores how to combine the power of Next.js 15 with UI components from Replay for truly scalable web development.

Understanding Behavior-Driven Reconstruction#

The traditional approach to UI development often involves wireframing, mockups, and then painstakingly translating these designs into code. This process is prone to errors and can be incredibly time-consuming. Replay offers a fundamentally different approach: behavior-driven reconstruction.

Instead of relying on static designs, Replay analyzes video recordings of real user interactions. This allows it to understand what users are trying to achieve, not just what they see on the screen. This understanding is then used to generate accurate and functional UI components, complete with event handlers and data bindings.

Here's a comparison:

FeatureScreenshot-to-CodeTraditional UI DevelopmentReplay
InputStatic ImagesManual Design SpecsVideo Recordings
Understanding User IntentLimited
Code AccuracyLowMediumHigh
Time SavingsModerateLowHigh
Multi-Page Support
Behavior Analysis

Setting Up Your Next.js 15 Project#

Let's start by setting up a new Next.js 15 project. This assumes you have Node.js and npm (or yarn) installed.

Step 1: Create a New Next.js Project#

Open your terminal and run the following command:

bash
npx create-next-app@latest my-replay-app

You'll be prompted with a few questions. Here's a suggested configuration:

  • Would you like to use TypeScript? Yes
  • Would you like to use ESLint? Yes
  • Would you like to use Tailwind CSS? Yes (Tailwind works great with Replay's style injection)
  • Would you like to use
    text
    src/
    directory? Yes
  • Would you like to use App Router? (recommended) Yes
  • Would you like to customize the default import alias? No

Step 2: Navigate to Your Project Directory#

bash
cd my-replay-app

Step 3: Install Dependencies#

While Tailwind is already installed, we might want to add some additional packages for API interactions and state management. For example,

text
swr
for data fetching:

bash
npm install swr

Integrating Replay-Generated Components#

Now comes the exciting part: integrating UI components generated by Replay into your Next.js 15 application.

Step 1: Generate UI Components with Replay#

Record a video of the desired user interaction or product flow you want to replicate. Upload this video to Replay. Replay will analyze the video and generate the corresponding UI components. You'll typically get a set of React components (in

text
.tsx
files) and associated CSS or Tailwind CSS styles.

💡 Pro Tip: When recording your video, focus on clear and deliberate interactions. This will help Replay accurately capture the user's intent.

Step 2: Copy the Generated Code into Your Project#

Download the generated code from Replay. Then, copy the component files (e.g.,

text
MyFormComponent.tsx
,
text
ProductCard.tsx
) and their associated style files (e.g.,
text
MyFormComponent.module.css
,
text
tailwind.config.js
) into your
text
src/app/components
directory (you might need to create this directory if it doesn't exist).

Step 3: Import and Use the Components#

Import the generated components into your Next.js pages or other components. For example, in your

text
src/app/page.tsx
:

typescript
// src/app/page.tsx import MyFormComponent from './components/MyFormComponent'; import ProductCard from './components/ProductCard'; export default function Home() { return ( <main className="flex min-h-screen flex-col items-center justify-between p-24"> <h1 className="text-4xl font-bold">Welcome to My Replay App</h1> <MyFormComponent /> <ProductCard /> </main> ); }

Step 4: Handle Data and Events#

Replay will generate basic event handlers (e.g.,

text
onClick
,
text
onChange
). You'll likely need to extend these handlers to connect them to your application's data layer and business logic.

For example, let's say

text
MyFormComponent
includes a form with an email input. You can use React's
text
useState
hook to manage the form's state and an API route to submit the data.

typescript
// src/app/components/MyFormComponent.tsx 'use client'; // Mark as a client component import { useState } from 'react'; interface MyFormComponentProps { onSubmit: (email: string) => void; } const MyFormComponent = ({ onSubmit }: MyFormComponentProps) => { const [email, setEmail] = useState(''); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSubmit(email); }; return ( <form onSubmit={handleSubmit}> <label htmlFor="email">Email:</label> <input type="email" id="email" value={email} onChange={(e) => setEmail(e.target.value)} /> <button type="submit">Submit</button> </form> ); }; export default MyFormComponent;

Then, in your

text
src/app/page.tsx
, you can define the
text
onSubmit
function and handle the API call:

typescript
// src/app/page.tsx 'use client'; // Mark as a client component import MyFormComponent from './components/MyFormComponent'; import ProductCard from './components/ProductCard'; import { useState } from 'react'; export default function Home() { const [message, setMessage] = useState(''); const handleSubmit = async (email: string) => { try { const response = await fetch('/api/submit-email', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email }), }); if (response.ok) { setMessage('Email submitted successfully!'); } else { setMessage('Failed to submit email.'); } } catch (error) { console.error('Error submitting email:', error); setMessage('An error occurred while submitting the email.'); } }; return ( <main className="flex min-h-screen flex-col items-center justify-between p-24"> <h1 className="text-4xl font-bold">Welcome to My Replay App</h1> <MyFormComponent onSubmit={handleSubmit} /> {message && <p>{message}</p>} <ProductCard /> </main> ); }

Finally, create the

text
/api/submit-email
route in
text
src/app/api/submit-email/route.ts
:

typescript
// src/app/api/submit-email/route.ts import { NextResponse } from 'next/server'; export async function POST(request: Request) { const { email } = await request.json(); // In a real application, you would save the email to a database. console.log('Received email:', email); return NextResponse.json({ message: 'Email received!' }); }

⚠️ Warning: Remember to handle errors and edge cases appropriately in your API routes.

Scaling with Next.js 15 and Replay#

Next.js 15 provides several features that contribute to the scalability of your application. Combined with the rapid UI generation of Replay, you can achieve impressive results.

  • Server Components: Next.js 15 encourages the use of Server Components, which can improve performance by rendering components on the server and sending only the necessary HTML to the client. Replay's generated components can be adapted to Server Components where appropriate, especially for static content.

  • Turbopack: Next.js 15 includes Turbopack, a Rust-based bundler that offers significantly faster build times than Webpack. This speeds up the development cycle and allows you to iterate more quickly on your UI.

  • Incremental Static Regeneration (ISR): ISR allows you to statically generate pages at build time and then revalidate them in the background. This ensures that your users always see the latest content without sacrificing performance. Replay can help you quickly generate the initial static content, and ISR keeps it fresh.

  • API Routes: Next.js API Routes provide a simple way to create serverless functions that can handle data fetching, form submissions, and other backend logic.

Replay's "Product Flow Maps" further aid in scaling by providing a visual representation of user journeys. This allows you to identify bottlenecks and optimize the user experience across multiple pages.

Advanced Techniques#

Style Injection#

Replay supports style injection, allowing you to apply custom styles to the generated components. This is particularly useful when you want to maintain a consistent look and feel across your application or when you need to override the default styles generated by Replay. You can use CSS modules, Tailwind CSS, or any other styling solution that integrates with Next.js.

Supabase Integration#

Replay integrates seamlessly with Supabase, a popular open-source Firebase alternative. This allows you to easily store and retrieve data from your Supabase database within your Replay-generated components. Replay can generate the necessary code to interact with your Supabase API, saving you even more time.

📝 Note: You'll need to configure your Supabase credentials in your Next.js project to enable this integration.

Here's an example of fetching data from Supabase using

text
supabase-js
and displaying it in a Replay-generated component:

typescript
// src/app/components/ProductList.tsx 'use client'; import { createClient } from '@supabase/supabase-js'; import { useState, useEffect } from 'react'; const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || ''; const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || ''; const supabase = createClient(supabaseUrl, supabaseKey); interface Product { id: number; name: string; description: string; price: number; } const ProductList = () => { const [products, setProducts] = useState<Product[]>([]); useEffect(() => { const fetchProducts = async () => { const { data, error } = await supabase .from('products') .select('*'); if (error) { console.error('Error fetching products:', error); } else { setProducts(data || []); } }; fetchProducts(); }, []); return ( <ul> {products.map((product) => ( <li key={product.id}> <h3>{product.name}</h3> <p>{product.description}</p> <p>${product.price}</p> </li> ))} </ul> ); }; export default ProductList;

Remember to install the Supabase client:

bash
npm install @supabase/supabase-js

And configure your environment variables in

text
.env.local
:

text
NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_URL NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY

Frequently Asked Questions#

Is Replay free to use?#

Replay offers both free and paid plans. The free plan has limitations on the number of videos you can analyze and the features you can access. The paid plans offer unlimited usage and access to all features, including Supabase integration and style injection.

How is Replay different from v0.dev?#

While both Replay and v0.dev aim to accelerate UI development, they differ in their approach. v0.dev primarily uses text prompts to generate UI components. Replay, on the other hand, analyzes video recordings of user interactions, allowing it to understand user intent and generate more accurate and functional UI components. Replay's behavior-driven approach often results in more production-ready code.

Can Replay generate code for complex animations?#

Replay can capture basic animations and transitions. However, for complex animations, you may need to manually add or modify the generated code.

What types of applications is Replay best suited for?#

Replay is particularly well-suited for applications with complex user flows, such as e-commerce platforms, SaaS dashboards, and mobile apps. It can also be used to quickly prototype new features or replicate existing UIs.

Does Replay support custom UI libraries?#

Replay primarily generates code using standard HTML, CSS, and JavaScript. However, you can easily integrate your own custom UI libraries by modifying the generated code. Replay's style injection feature also allows you to apply custom styles from your UI library.


Ready to try behavior-driven code generation? Get started with Replay - transform any video into working code in seconds.

Ready to try Replay?

Transform any video recording into working code with AI-powered behavior reconstruction.

Launch Replay Free