v0 by Vercel
Vercel offers a new service called v0. By using this service, you can easily develop web components using generative AI. This document introduces the standard procedure for using v0.
Introducing v0
Vercel is a company that provides services for hosting various applications. They also offer Next.js, a useful tool for building websites.
The v0 service, which we will cover this time, allows you to create web components using generative AI.
v0 by Vercel
When you access the site, a simple page where you just need to enter commands is displayed as shown below.
You can input prompts on this screen to generate various UIs. Japanese UI is also available in the preview.
About Pricing Plans
There are plans for using v0, ranging from a free plan with limited usage and features to a subscription plan. For evaluation purposes, you can use the free plan to test it out.
Refer to the following page for pricing plans.
Creating Components
Generating with Chat
This time, we specified the following prompt in the chatbox in Japanese.
Create a list of 12 topics for the top page of a blog site, arranged in 4 columns on large screens, 2 columns on small screens, and vertically on smartphones.
The generated screen is as follows.
Add a project to save the generated component. Select Project from the menu on the left, and create a new project with New Project. This time, name it Blog.
After creating the project, go back to the component you created earlier and click the Deploy button in the upper right corner. The project to deploy will be displayed, so specify Blog.
After a while, the component you created will be deployed to Vercel.
As a result, you can check the page as shown below.
Checking the Generated Code
You can check the code from the screen above by clicking the tab on the right.
The generated code is as follows.
Using Components in Next.js
Creating a Next.js Project
We will use the created components directly in Next.js. Let’s prepare a vanilla Next.js project and display the components. First, create a Next.js project.
Create the project as follows.
To make it a Next.js project without sample content, delete the sample data. The changes are as follows.
Now, Next.js is ready.
Adding Created Components
To use the components created with v0, there is a command provided in the management screen’s upper right corner to add the code.
Execute the provided command at the top of the Next.js project. For the initial installation, the following prompts will appear.
- Install shadcn@2.1.6: Yes
- Create Components.json: Yes
- Style: New York
- Base color: Neutral
- CSS Variables: Yes
- Overwrite page.tsx: Yes
After the above settings, the project will be automatically updated.
The following files will be added or updated. The added files are highlighted.
- components.json
- package-lock.json
- package.json
- tailwind.config.ts
Directorysrc
Directoryapp
- globals.css
- page.tsx
Directorycomponents
Directoryui
- card.tsx
- TopicCard.tsx
Directorylib
- data.ts
- types.ts
- utils.ts
Running the Project
Now the created components have been added to the project. Run the following command.
The result is as follows, displaying the screen created with v0.
When executed, the component generation is successful, but errors are also displayed.
This occurs because the images are not available in the public directory. Create the following SVG file.
After placing the above file, the following error message appears.
To enable the use of SVG files, apply the following settings to next.config.js.
Now the created image is displayed.
The sample code up to this point is available on GitHub.
Generating UI from Images
This time, we will access the top page of the Sitecore XM Cloud documentation site and proceed with creating components from its screenshot.
-
Prepare the image
-
Upload it to the v0 prompt
-
Execute the component generation. After a while, the component will be generated, and you can check the component information and preview as shown below.
-
Open the preview to see that items like dropdown menus are also generated.
Thus, it is possible to create components using images.
Sitecore Integration
The components generated so far were based on Next.js, but now v0.dev can output results that have learned from Sitecore Documentation information. Simply add #sitecore
to the prompt to support it.
As shown above, you can easily obtain a prototype for use with Sitecore Headless SXA using v0.dev.
-
Add
#sitecore
to the prompt and execute it. -
After a while, two files will be generated. Note that the preview cannot be executed as there is no Sitecore environment.
The generated code includes the following:
- Implementation of the carousel using react-slick
- Fields
image
,title
, anddescription
are assumed to be retrieved from Sitecore.
-
Execute the following prompt additionally on the above result.
-
After a while, the implementation of the created component was changed to the code based on Embla Carousel.
Summary
This time, we confirmed the procedure for generating sample components for use in Next.js using v0. It is very convenient to be able to generate not only from prompts but also from images.
References
Update History
- 2024-12-16 Added information about #sitecore support by v0.dev - Sitecore Integration