Vercel Visual Editing is a feature within the Vercel site preview that adds a clickable link to any content powered by a Builder data model on your site. When clicked, this link will take you to the corresponding content entry within Builder. Once set up for your project, it will look like the following example.
The first requirement to using Vercel Visual Editing in your Builder-powered Next.js site is to have something on your site powered by a Builder data model.
Next, use the Builder v3 Content API. Upgrade your React SDK to the latest version if your version does not support the apiVersion
setting.
npm update @builder.io/react@latest
With an updated SDK version that supports the Builder v3 content API, add the following to your Next.js project.
- Better support for localization (coming soon): The content API will provide improved support for localization, including querying based on localization features.
- Support for multi-level nested references (coming soon): The content API will allow you to query, resolve, and return content that has nested references of other contents and symbols.
import { builder } from "@builder.io/react";
builder.init('YOUR_BULDER_PUBLIC_API_KEY');
builder.apiVersion = "v3";
Then, when making the call to fetch the data from Builder, you need to include the vercelPreview
parameter and set it to true
.
Make sure to include the logic that only sets this flag to true
when Vercel is in preview mode, so your production deployments do not have the additional metadata that is added to make the Edit button display.
const content = await builder.getAll("SOME_DATA_MODEL_NAME", {
options: {
vercelPreview: process.env.VERCEL_ENV === 'preview',
},
});
For more detail, read Vercel's documentation on Visual Editing.
Looking to hire a third party to help with your project?
Submit a project request and our partnerships team will reach out to connect you with an Expert from our partner ecosystem.