Back to Blog
January 5, 20268 min readMigrating from Create

Migrating from Create React App to Next.js 14 Using Replay

R
Replay Team
Developer Advocates

TL;DR: Replay drastically simplifies migrating a Create React App (CRA) project to Next.js 14 by automatically generating Next.js code from video recordings of your CRA app's functionality.

Migrating from Create React App (CRA) to Next.js 14 can unlock significant performance gains, SEO improvements, and a smoother developer experience. However, manually rewriting components and logic is a tedious and error-prone process. What if you could simply show the desired behavior and have the code generated for you? That's where Replay comes in.

The Pain of Manual CRA to Next.js Migration#

Manually migrating a CRA project to Next.js involves:

  • Rewriting components to leverage server-side rendering (SSR) or static site generation (SSG).
  • Implementing routing based on the Next.js file system.
  • Handling data fetching with
    text
    getServerSideProps
    or
    text
    getStaticProps
    .
  • Updating styling solutions to work with Next.js's module system.

This process is time-consuming and requires a deep understanding of both CRA and Next.js. Furthermore, ensuring that the migrated application functions identically to the original CRA app is a major challenge.

Replay: Automating the Migration with Behavior-Driven Reconstruction#

Replay offers a novel approach to CRA to Next.js migration by using video recordings of your existing CRA application as the source of truth. Instead of painstakingly rewriting code, you record yourself interacting with your CRA app, demonstrating the desired functionality. Replay then leverages advanced AI to analyze the video and generate equivalent Next.js code, understanding not just what the UI looks like, but how it behaves.

How Replay Works#

Replay employs a "Behavior-Driven Reconstruction" methodology. It analyzes video recordings to understand user interactions, data flow, and UI state transitions. This information is then used to generate functional Next.js code, complete with:

  • Page routing based on the Next.js file system.
  • Data fetching using
    text
    getServerSideProps
    or
    text
    getStaticProps
    .
  • Component structure that mirrors the original application's UI.
  • Styling that preserves the look and feel of the CRA app.

Key Benefits of Using Replay for Migration#

  • Speed: Significantly reduces the time required for migration compared to manual rewriting.
  • Accuracy: Ensures that the migrated application functions identically to the original CRA app by analyzing its behavior.
  • Reduced Risk: Minimizes the risk of introducing errors during the migration process.
  • Accessibility: Makes Next.js migration accessible to developers with varying levels of experience.
  • Multi-Page Generation: Replay can handle complex, multi-page applications, generating the necessary Next.js routes and components.

Comparison with Other Migration Approaches#

FeatureManual MigrationScreenshot-to-CodeReplay
SpeedSlowMediumFast
AccuracyVariableLowHigh
ComplexityHighMediumLow
Behavior AnalysisManualLimited
Video Input
State ManagementManualIgnored
Data FetchingManualIgnored

Step-by-Step Guide: Migrating with Replay#

Here's a practical example of how you might use Replay to migrate a simple CRA-based to-do list application to Next.js 14.

Step 1: Record Your CRA Application#

Use a screen recording tool (like Loom or OBS Studio) to record yourself interacting with your to-do list application. Demonstrate the following actions:

  1. Adding a new task.
  2. Marking a task as complete.
  3. Deleting a task.
  4. Filtering tasks (if applicable).

Ensure the recording is clear and captures all relevant UI elements and interactions. The more comprehensive your recording, the better Replay can understand the application's behavior.

💡 Pro Tip: Record each distinct flow (e.g., adding a task, deleting a task) as separate videos for better organization and accuracy.

Step 2: Upload the Video to Replay#

Upload the recorded video to Replay. Replay's AI engine will begin analyzing the video to understand the application's structure and behavior.

Step 3: Configure Replay Settings#

Configure the following settings within Replay:

  • Target Framework: Select Next.js 14.
  • Styling Method: Choose your preferred styling solution (e.g., CSS Modules, Styled Components, Tailwind CSS).
  • Data Fetching: Specify how data should be fetched (e.g., using
    text
    getServerSideProps
    ,
    text
    getStaticProps
    , or client-side fetching).
  • Supabase Integration: If your CRA app uses Supabase, configure the integration in Replay to automatically generate the necessary API calls and data models.

Step 4: Generate the Next.js Code#

Click the "Generate Code" button. Replay will generate the Next.js code based on the video analysis and your configuration settings. This process may take a few minutes, depending on the complexity of the application.

Step 5: Review and Refine the Code#

Review the generated Next.js code. Replay provides a code editor within its interface, allowing you to make any necessary adjustments or refinements.

typescript
// Example of a generated Next.js page component import { useState, useEffect } from 'react'; interface Task { id: number; text: string; completed: boolean; } export default function TodoList() { const [tasks, setTasks] = useState<Task[]>([]); useEffect(() => { // Fetch tasks from an API endpoint (e.g., Supabase) const fetchTasks = async () => { const response = await fetch('/api/tasks'); const data = await response.json(); setTasks(data); }; fetchTasks(); }, []); const handleAddTask = async (text: string) => { // Add a new task to the API const response = await fetch('/api/tasks', { method: 'POST', body: JSON.stringify({ text }), headers: { 'Content-Type': 'application/json' }, }); const newTask = await response.json(); setTasks([...tasks, newTask]); }; return ( <div> <h1>Todo List</h1> {/* ... UI elements for displaying and managing tasks ... */} </div> ); }

📝 Note: Replay attempts to generate production-ready code, but manual review and testing are always recommended.

Step 6: Deploy Your Next.js Application#

Once you are satisfied with the generated code, deploy your Next.js application to your preferred hosting provider (e.g., Vercel, Netlify).

Advanced Features: Style Injection and Product Flow Maps#

Replay goes beyond basic code generation by offering advanced features that further streamline the migration process:

  • Style Injection: Replay can automatically inject styles from your CRA application into the generated Next.js components, preserving the original look and feel.
  • Product Flow Maps: Replay generates visual maps of the user flows within your application, helping you understand the application's structure and identify potential areas for improvement.

Real-World Example: E-commerce Product Page Migration#

Imagine you have a product page in your CRA e-commerce app. It displays product details, allows users to add the product to their cart, and shows related products. Manually migrating this page to Next.js would involve:

  1. Setting up Next.js routing for the product page.
  2. Implementing server-side data fetching to retrieve product details.
  3. Rewriting the component to use Next.js-compatible styling.
  4. Ensuring that the "add to cart" functionality works correctly with the new data fetching approach.

With Replay, you can simply record yourself interacting with the product page in your CRA app, demonstrating the desired behavior. Replay will then generate the Next.js code, handling routing, data fetching, and styling automatically.

jsx
// Example of generated Next.js code for a product page import { GetServerSideProps } from 'next'; interface Product { id: number; name: string; description: string; price: number; } interface Props { product: Product; } export const getServerSideProps: GetServerSideProps<Props> = async (context) => { const { id } = context.params; const response = await fetch(`https://api.example.com/products/${id}`); const product = await response.json(); return { props: { product, }, }; }; const ProductPage = ({ product }: Props) => { return ( <div> <h1>{product.name}</h1> <p>{product.description}</p> <p>Price: ${product.price}</p> {/* ... Add to cart button and related products ... */} </div> ); }; export default ProductPage;

⚠️ Warning: While Replay automates much of the migration process, it's essential to thoroughly test the generated code to ensure it meets your specific requirements.

Frequently Asked Questions#

Is Replay free to use?#

Replay offers a free tier with limited features and usage. Paid plans are available for more extensive use and access to advanced features like Supabase integration and style injection. Check the Replay website for the most up-to-date pricing information.

How is Replay different from v0.dev?#

While both Replay and v0.dev aim to generate code, they differ significantly in their approach. v0.dev primarily uses text prompts and existing UI libraries to generate code snippets. Replay, on the other hand, analyzes video recordings of existing applications to understand user behavior and generate code that accurately replicates that behavior. Replay focuses on behavior-driven reconstruction, making it particularly well-suited for migrating existing applications.

What styling solutions does Replay support?#

Replay supports a variety of popular styling solutions, including CSS Modules, Styled Components, and Tailwind CSS. You can select your preferred styling solution during the configuration process.

Does Replay support complex state management solutions like Redux or Zustand?#

Replay can understand and generate code for applications that use complex state management solutions. However, the accuracy of the generated code may depend on the complexity of the state management implementation and the clarity of the video recording.

Can Replay handle animations and transitions?#

Replay can analyze and generate code for simple animations and transitions. However, complex animations may require manual adjustments to the generated code.


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