Skip to content
Dashboard

Sanity is now available on the Vercel Marketplace

Marketplace Team

Link to headingGet started with the integration

src/sanity/schemaTypes/postType.ts
import { defineField, defineType } from "sanity";
export const postType = defineType({
name: "post",
title: "Post",
type: "document",
fields: [
defineField({ name: "title", type: "string" }),
defineField({ name: "slug", type: "slug", options: { source: "title" } }),
defineField({ name: "body", type: "array", of: [{ type: "block" }] }),
],
});

Define a post document type with title, slug, and rich text body fields

src/sanity/schemaTypes/index.ts
import { postType } from "./postType";
export const schemaTypes = [postType];

Export all schema types for Sanity Studio to use

src/sanity/lib/client.ts
import { createClient } from "next-sanity";
export const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: "production",
apiVersion: "2024-01-01",
useCdn: false,
});

Create a reusable client configured with your project's environment variables

src/app/page.tsx
import { client } from "@/sanity/lib/client";
const POSTS_QUERY = `*[_type == "post"] | order(publishedAt desc)[0...12]{
_id, title, slug, publishedAt
}`;
export default async function HomePage() {
const posts = await client.fetch(POSTS_QUERY);
return (
<ul>
{posts.map((post) => (
<li key={post._id}>{post.title}</li>
))}
</ul>
);
}

Fetch the 12 most recent posts and render them as a list

Ready to deploy?