Back to Blog
January 4, 20267 min readTechnical Deep Dive:

Technical Deep Dive: How Replay creates component with storybook for reuse from video

R
Replay Team
Developer Advocates

TL;DR: Replay uses video analysis powered by Gemini to reconstruct UI components and generate Storybook stories for maximum reusability, offering a behavior-driven approach to code generation.

Technical Deep Dive: Reconstructing UI Components with Storybook from Video#

The holy grail of UI development is efficient reusability. We all strive for DRY (Don't Repeat Yourself) code, but often find ourselves rebuilding similar components from scratch. Screenshot-to-code tools offer a partial solution, but they lack the crucial understanding of user intent. What was the user trying to do?

Replay addresses this gap by analyzing video recordings of user interactions. Leveraging Gemini, Replay reconstructs UI components with a deep understanding of the intended behavior, and then generates Storybook stories, ensuring these components are not just functional, but also easily reusable and testable. This "Behavior-Driven Reconstruction" unlocks a new level of productivity for front-end teams.

The Problem with Traditional Approaches#

Traditional methods of component creation and reuse often fall short. Consider these common scenarios:

  • Manual Recreation: Rebuilding a component from scratch every time it's needed. This is time-consuming and error-prone.
  • Copy-Pasting: Duplicating code across multiple projects, leading to maintenance nightmares.
  • Screenshot-to-Code Limitations: Generating code from static images misses crucial interaction details and underlying logic.

The key is capturing the behavior associated with the UI element. How does it respond to user input? What are its different states? Screenshot-to-code tools simply can't answer these questions.

Replay's Behavior-Driven Reconstruction#

Replay tackles this challenge by analyzing video recordings of user interactions. Here's how it works:

  1. Video Analysis: Replay ingests a video recording of a user interacting with a UI.
  2. Behavioral Understanding: Gemini analyzes the video to understand the user's actions, identifying elements like button clicks, form submissions, and state changes.
  3. Component Reconstruction: Replay reconstructs the UI component based on the observed behavior, generating clean and functional code.
  4. Storybook Story Generation: Replay automatically generates Storybook stories for the reconstructed component, making it easy to visualize, test, and reuse.

This approach ensures that the generated components are not just visually similar to the original, but also functionally equivalent and easily maintainable.

Key Features in Action#

Let's explore some of Replay's key features with practical examples:

Multi-Page Generation

Replay can analyze videos that span multiple pages or routes, reconstructing complex workflows. Imagine recording a user signing up for an account. Replay can capture the entire flow, from the initial registration form to the email verification page, and generate components for each step.

Supabase Integration

Replay seamlessly integrates with Supabase, allowing you to connect your generated components to a backend database. This simplifies data management and persistence.

Style Injection

Replay intelligently extracts and applies styles from the video, ensuring that the generated components match the original design. You can further customize these styles using CSS or your preferred styling library.

Product Flow Maps

Replay can automatically generate product flow maps based on the video analysis. This provides a visual representation of the user's journey, making it easier to understand and optimize the user experience.

Comparing Replay to Other Tools#

Here's a comparison of Replay with other code generation tools:

FeatureScreenshot-to-Codev0.devReplay
Input TypeScreenshotText promptVideo
Behavior AnalysisPartial (via prompt)
Multi-Page SupportLimitedLimited
Storybook Generation
Style ExtractionBasicBasicAdvanced
Supabase Integration

📝 Note: "Partial" behavior analysis in v0.dev relies heavily on the prompt provided and doesn't inherently understand user actions from a visual recording.

Creating a Component with Storybook: A Step-by-Step Guide#

Let's walk through the process of creating a reusable component with Storybook using Replay.

Step 1: Record the User Interaction

Record a video of yourself interacting with the UI component you want to reconstruct. For example, let's say you have a custom button component with different states (default, hover, active). Record yourself clicking the button and observing its state changes.

Step 2: Upload the Video to Replay

Upload the video to the Replay platform. Replay will analyze the video and identify the relevant UI elements and their associated behaviors.

Step 3: Review and Refine the Generated Code

Replay will generate the code for the button component, including its different states and event handlers. Review the code and make any necessary refinements.

Step 4: Generate the Storybook Story

Replay will automatically generate a Storybook story for the button component. This story will allow you to visualize the component in different states and interact with it in a controlled environment.

Step 5: Integrate the Component into Your Project

Copy the generated code and Storybook story into your project. You can now reuse the button component throughout your application.

Code Example: Generated Button Component#

Here's an example of the code that Replay might generate for a simple button component:

typescript
import React, { useState } from 'react'; import './Button.css'; // Example CSS file interface ButtonProps { label: string; onClick: () => void; } const Button: React.FC<ButtonProps> = ({ label, onClick }) => { const [isActive, setIsActive] = useState(false); const handleClick = () => { setIsActive(true); onClick(); setTimeout(() => setIsActive(false), 100); // Simulate a brief active state }; return ( <button className={`button ${isActive ? 'button--active' : ''}`} onClick={handleClick} > {label} </button> ); }; export default Button;

And here's the corresponding Storybook story:

javascript
import React from 'react'; import Button from './Button'; export default { title: 'Components/Button', component: Button, }; const Template = (args) => <Button {...args} />; export const Default = Template.bind({}); Default.args = { label: 'Click Me', onClick: () => alert('Button Clicked!'), };

💡 Pro Tip: Replay's style extraction is surprisingly accurate, but you can always fine-tune the generated CSS to match your project's design system perfectly.

Benefits of Using Replay#

  • Increased Productivity: Automate the process of component creation and Storybook story generation.
  • Improved Reusability: Ensure that components are easily reusable and testable.
  • Enhanced Accuracy: Capture the intended behavior of UI elements, not just their visual appearance.
  • Reduced Errors: Minimize manual coding and potential for human error.
  • Faster Iteration: Quickly prototype and iterate on UI designs.
  • Better Understanding: Visual product flow maps help the team understand the user experience.

⚠️ Warning: While Replay significantly reduces development time, it's crucial to review and refine the generated code to ensure it meets your specific requirements and coding standards.

Real-World Use Cases#

Replay can be used in a variety of real-world scenarios, including:

  • Reconstructing legacy UI components: Quickly modernize outdated UI elements by recording their behavior and generating new components.
  • Creating design system components: Build a comprehensive design system by recording common UI patterns and generating reusable components.
  • Prototyping new features: Rapidly prototype new features by recording user interactions and generating functional UI components.
  • Automating UI testing: Generate Storybook stories for automated UI testing.

Frequently Asked Questions#

Is Replay free to use?#

Replay offers a free tier with limited usage. Paid plans are available for higher usage and advanced features. Check the Replay pricing page for details.

How is Replay different from v0.dev?#

While both Replay and v0.dev aim to accelerate UI development, they differ significantly in their approach. v0.dev relies on text prompts to generate code, while Replay analyzes video recordings to understand user behavior. This "Behavior-Driven Reconstruction" allows Replay to capture more nuanced interactions and generate more accurate and reusable components. Replay also automatically generates Storybook stories for components, a feature not available in v0.dev. Replay focuses on understanding what the user is doing and why, not just generating code from a description.

What types of videos can Replay analyze?#

Replay can analyze screen recordings of any application or website. The video should clearly show the user interacting with the UI elements you want to reconstruct.

What frameworks does Replay support?#

Replay currently supports React, with plans to add support for other popular frameworks in the future.


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