Issues with array field and reference type in navMenu schema
Based on the documentation, if you want to hide the media element in preview configurations, the standard approach is to simply omit the media property from your preview configuration entirely.
When you don't need a media preview, just don't include it in your select or prepare functions:
preview: {
select: {
title: 'title',
subtitle: 'description'
// No media property defined
}
}Or if you're using prepare:
preview: {
select: {
title: 'title'
},
prepare({title}) {
return {
title: title,
subtitle: 'Some subtitle'
// No media property returned
}
}
}According to the preview configuration documentation, the preview system accepts title, subtitle, and media properties - but they're all optional. You only need to include the ones you want to display.
If you have a field that sometimes has an image, you can conditionally handle it in the prepare function. A common pattern is to use an icon as a fallback when media isn't available:
import { DocumentIcon } from '@sanity/icons'
preview: {
select: {
title: 'title',
image: 'image'
},
prepare({title, image}) {
return {
title: title,
media: image ?? DocumentIcon // Use icon when no image exists
}
}
}This approach is shown in the Page Building course as a best practice for handling optional media.
The key takeaway: you don't need to pass null or false to hide media - just don't include the media property at all in your preview configuration. This is the documented, standard way to control what appears in your previews.
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.