How to display field value in Sanity schema preview section?

19 replies
Last updated: Nov 29, 2025
Can I return the title that is given in the field section and put that in the preview section and how should I do that?
fields: [
            {
              title: 'Title',
              name: 'title',
              type: 'string',
            },
],
preview: {
            prepare() {
              return {
                icon: MdTextFields,
                title: 'how to get the above title ???',
              }
            }
          }
        },
AI Update

Yes, absolutely! You need to use the select property to pass the field value to your prepare function. Here's how to fix your code:

fields: [
  {
    title: 'Title',
    name: 'title',
    type: 'string',
  },
],
preview: {
  select: {
    title: 'title'  // This selects the 'title' field
  },
  prepare({title}) {  // The selected value is passed here as a parameter
    return {
      icon: MdTextFields,
      title: title,  // Now you can use it!
    }
  }
}

The key is understanding how Sanity's preview configuration works:

  1. select - Tells Sanity which fields to extract from your document
  2. prepare - Receives those selected fields as parameters and returns what to display

You can also simplify this if you're just passing the title through without transformation:

preview: {
  select: {
    title: 'title'
  }
  // No prepare needed - Sanity will automatically use the title
}

This pattern works for any field in your schema. You can select multiple fields too:

preview: {
  select: {
    title: 'title',
    subtitle: 'description',
    media: 'image'
  },
  prepare({title, subtitle, media}) {
    return {
      title: title,
      subtitle: subtitle,
      media: media ?? MdTextFields  // Use icon as fallback
    }
  }
}

The select object uses the field names from your schema, and those values become available in the prepare function parameters.

Show original thread
19 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.

Was this answer helpful?