Building a Sanity document if I have a field for categories that is an array of references:
defineField({
name: 'categories',
title: 'Categories',
type: 'array',
of: [
{
options: {
disableNew: true,
},
type: 'reference',
to: [
{
type: 'blogCategory',
},
],
},
],
group: 'details',
validation: (Rule) => Rule.required().unique(),
}),
in that document's preview
I'm trying to render the referenced categories in the subtitle
:
attempt:
preview: {
select: {
title: 'title',
media: 'image',
categories: 'categories',
},
prepare(selection) {
const {title, media, categories} = selection
return {
title,
media: media ? media : SlPicture,
subtitle: categories,
}
},
},
in my research, I've read through:
- List Previews
- Sanity Preview Mode not intiating
- You're importing a component that needs useState. It only works in a Client Component, but none of its parents are marked with "use client"
- Sanity draft preview not working with block content
- Reference to array of objects in Sanity
In Sanity how can I render the array of category references in the subtitle
?