v0 Dev Tutorial: Build React Apps with Vercel v0

Updated 3 min read

Generating clean React code with artificial intelligence often breaks existing Tailwind setups or drops critical UI dependencies. This guide teaches frontend and full-stack developers how to structure prompts, configure their local workspace, and import components smoothly. By the end, you will have a working workflow connecting the browser tool, command line, and SDK directly to your project.

Watch the video on YouTube

Before you start

  • Node.js 18 or later (Node.js 22 recommended)
  • Basic knowledge of React, Next.js App Router, and Tailwind CSS
  • A free v0 account at v0.app

What v0 Is and How It Works

v0 has expanded from an isolated component creator into an agentic system that builds full-stack interfaces. It relies on the Next.js App Router, React, Tailwind CSS, Lucide icons, and Radix-backed primitives. Because it generates code against these specific libraries, matching your local tech stack to these defaults ensures visual fidelity and functional consistency.

Prompting Principles for Reliable Code

Submitting massive prompts for complete applications frequently leads to hallucinated logic, bloated single-file components, and rapid consumption of generation credits. Focus on one interface element at a time, such as an isolated form or an individual dashboard widget.

Declare required libraries early, and outline distinct operational states such as loading skeletons, empty states, and viewport responsiveness. Structuring your requirements clearly upfront minimizes rework downstream.

Setting Up a Local Next.js Workspace

Preparing your local environment requires a clean Next.js foundation paired with compatible styling configuration. Run the project initialization command below using standard defaults for TypeScript and Tailwind CSS.

Next, execute the setup command to generate the components.json configuration file and install the necessary utility packages. This step prepares your directory structure to receive generated code cleanly.

TerminalNot verified in our test run
# Initialize Next.js application non-interactively using npx -y
npx -y create-next-app@latest v0-workspace --typescript --tailwind --eslint --app --no-src-dir --import-alias "@/*" --use-npm
# Enter workspace and initialize shadcn with default configuration
cd v0-workspace && npx -y shadcn@latest init -d
# Install common UI helper dependencies
npm install lucide-react clsx tailwind-merge
Output from our test run
$ npx -y create-next-app@latest v0-workspace --typescript --tailwind --eslint --app --no-src-dir --import-alias
"@/*" --use-npm

Using defaults for unprovided options:

  --ts                    TypeScript (use --js for JavaScript)
  --no-react-compiler     No React Compiler (use --react-compiler for React Compiler)
  --cache-components      Cache Components (use --no-cache-components for No Cache Components)
  --agents-md             AGENTS.md (use --no-agents-md for No AGENTS.md)
  --no-agent-feedback     No agent feedback (use --agent-feedback for Agent feedback)

Creating a new Next.js app in /root/v0-workspace.

Using npm.

Initializing project with template: app-tw

Installing dependencies:
- next
- react
- react-dom

Installing devDependencies:
- @tailwindcss/turbopack
- @types/node
- @types/react

Importing Components into Your Project

When you finish designing an element on the web canvas, export it directly into your local repository using the CLI instead of copy-pasting raw code. The command below was tested to install foundational UI primitives into the local directory, automatically resolving dependencies and configuring matching styles.

Verifying the contents of the components/ui directory confirms that files such as card.tsx and button.tsx are in place and ready to use in your application views.

TerminalTested: all commands succeeded
# Install base UI primitives used by v0 components
npx shadcn@latest add card button --yes
# Verify generated component primitives exist
ls -la components/ui
Output from our test run
$ npx shadcn@latest add card button --yes
✔ Checking registry.
✔ Created 1 file:
  - components/ui/card.tsx
ℹ Skipped 1 file: (files might be identical, use --overwrite to overwrite)
  - components/ui/button.tsx
$ ls -la components/ui
total 16
drwxr-xr-x 2 root root 4096 Nov 18 15:20 .
drwxr-xr-x 3 root root 4096 Nov 18 15:18 ..
-rw-r--r-- 1 root root 3230 Nov 18 15:18 button.tsx
-rw-r--r-- 1 root root 2620 Nov 18 15:20 card.tsx
$

Building with the Official v0 SDK

Vercel provides a programmatic client for automating generations or integrating agentic builders directly into your internal tools. Install the official library using the package manager command below.

Make sure to define your V0_API_KEY strictly in your local environment file without exposing it to client-side bundles. Running generations from server environments protects your account credentials.

TerminalNot verified in our test run
# Install the official v0 SDK
npm install v0
Output from our test run
$ npm install v0

added 19 packages, and audited 565 packages in 38s

219 packages are looking for funding
  run `npm fund` for details

23 vulnerabilities (2 moderate, 21 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
$

Writing an SDK Generation Script

You can automate component requests by initializing the V0 client on the server. The script below reads the environment key and dispatches a generation request using the chats.create method with a detailed prompt.

Once execution finishes, the returned chat object provides the unique identifier and a direct web preview address. You can expand this pattern to save files directly to your components directory.

generate-component.ts
import { V0 } from 'v0';

const apiKey = process.env.V0_API_KEY;
if (!apiKey) {
  throw new Error('V0_API_KEY environment variable is required.');
}

const v0 = new V0({ apiKey });

async function main() {
  const chat = await v0.chats.create({
    message: 'Create a responsive user profile card with avatar, status badge, and stats using Tailwind CSS and Lucide icons.',
  });

  console.log('Chat created with ID:', chat.id);
  console.log('Component preview:', chat.webUrl);
}

main().catch(console.error);

Connecting v0 via Model Context Protocol

You can connect your local development editor directly to generation services using the Model Context Protocol. Adding the configuration below allows compatible AI assistants to interface with the remote service through npx mcp-remote.

The protocol authenticates via your browser session, removing the need to store static tokens in local configuration files while allowing your editor to request UI changes directly.

mcp-config.json
{
  "mcpServers": {
    "v0": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://v0.app/api/mcp"
      ]
    }
  }
}

Production Hardening and Security

Generated code provides rapid structural scaffolding, but backend logic requires manual security hardening before production release. Review all server actions to ensure user authentication, session permissions, and payload validation are implemented.

Add rate limiting to sensitive routes, and verify that no fallback mock data or static keys remain in your source files. Treating generated code like third-party input ensures your application remains secure.

Wrap-up

Following a structured component-first workflow allows you to leverage AI generation without degrading code quality or exposing sensitive tokens. By pairing disciplined prompting with local CLI tooling and automated server scripts, you can prototype quickly while keeping your codebase stable.

FAQ

Why should I avoid asking for an entire application in one prompt?

Large monolithic prompts frequently cause hallucinated logic, bloated code, and quick exhaustion of message credits. Starting with small, modular components yields cleaner and more maintainable code.

What core technologies does v0 generate by default?

The platform builds applications using the Next.js App Router, React, Tailwind CSS, Lucide icons, and shadcn UI primitives built on Radix UI.

How do I export components into my local codebase?

You can pull components directly into your local project using either the npx v0@latest add command or the shadcn CLI with the export URL provided in the web interface.

How does authentication work when using the Model Context Protocol?

The protocol connects through npx mcp-remote and authenticates directly through browser OAuth, meaning you do not need to store static API keys in your editor configuration.

Sources

Subscribe for more tested tutorials