0

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:

In Sanity how can I render the array of category references in the subtitle?

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

0 Answers0