Next.js quick start

Defining a schema

A new Sanity Studio project has no schema types registered, so there is nothing to edit yet. Define your first document type and register it.

1

This step continues from Setting up your studio, which creates a studio in a studio-hello-world folder. The file paths in this article assume that folder.

2Create a new document type

Create a new file in your studio's schemaTypes folder called postType.ts with the following code, which defines a set of fields for a new post document type.

3Register the post type in your studio's schema

Import the type into the schemaTypes array in the index.ts file in the same folder.

4Publish your first document

When you save these two files, your studio reloads automatically and shows your first document type.

To create and publish your first post document:

  • In the navbar, click Create new document, then select Post.
  • Enter a value for Title.
  • Click Generate beside the Slug field.
  • Click Publish.

The title, slug, and publishedAt fields are all required. publishedAt is filled in for you by its initialValue, so enter a title and generate a slug before you publish. Otherwise Publish stays disabled and its tooltip reads There are validation errors that need to be fixed before this document can be published.

Was this page helpful?