Managing fields in Sanity Studio: grouping and organizing schemas
Yes, absolutely! You can definitely do something like that in Sanity. This is a great pattern for creating reusable field definitions.
What you're showing is extracting field definitions into separate constants and then spreading them into your schema. This works perfectly in Sanity and is actually a recommended practice for keeping your schemas DRY (Don't Repeat Yourself).
Here's how you can do it:
// Define reusable fields
const title = {
name: 'title',
type: 'string',
validation: (Rule) => Rule.required().error('The title is required.'),
};
const description = {
name: 'description',
type: 'text',
validation: (Rule) => Rule.required().error('The description is required.'),
};
// Use them in your schema
export default {
name: 'Foo',
type: 'document',
fields: [title, description],
};Even better with TypeScript helpers:
If you're using TypeScript, you can use defineField for better type safety:
import {defineField, defineType} from 'sanity'
// Define reusable fields
const title = defineField({
name: 'title',
type: 'string',
validation: (Rule) => Rule.required().error('The title is required.'),
});
const description = defineField({
name: 'description',
type: 'text',
validation: (Rule) => Rule.required().error('The description is required.'),
});
// Use them in your schema
export default defineType({
name: 'Foo',
type: 'document',
fields: [title, description],
});Common use cases:
This pattern is especially useful when:
- You have common fields like
title,slug,publishedAtthat appear across multiple document types - You want to maintain consistent validation rules across schemas
- You're building a page builder with reusable field definitions
- You need to share field configurations between related schemas
You can even organize these in a separate file like fields.ts and import them wherever needed!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.