How to define an empty or placeholder object within a schema array in Sanity.io using a custom input component.
Yes, you can definitely create an empty or placeholder object within a schema array! This is useful for identifiers, dividers, or markers within content blocks.
Here's how you can define a minimal object type in your array:
{
name: 'contentBlocks',
type: 'array',
of: [
{
type: 'block' // regular content
},
{
name: 'placeholder',
type: 'object',
fields: [
{
name: 'identifier',
type: 'string',
title: 'Identifier',
initialValue: 'marker'
}
],
preview: {
select: {
identifier: 'identifier'
},
prepare({identifier}) {
return {
title: `--- ${identifier || 'Placeholder'} ---`
}
}
}
}
]
}If you want an even more minimal placeholder that's truly "empty" (no fields at all), you can do:
{
name: 'divider',
type: 'object',
fields: [
{
name: 'hidden',
type: 'string',
hidden: true,
initialValue: 'divider'
}
],
preview: {
prepare() {
return {
title: '--- Divider ---',
subtitle: 'Visual separator'
}
}
}
}The key points:
- You need at least one field (even if hidden) for the object to be valid
- Use the
previewproperty to make it visually identifiable in the array - The
_keyproperty is automatically added to track each array item
This approach works great for creating visual separators, section markers, or any kind of structural identifier in your content blocks. The array fields documentation explains how arrays support multiple member types and how each item gets tracked with unique keys.
Show original thread6 replies
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.