Watch a live product demo 👀 See how Sanity powers richer commerce experiences

How to use a Custom Preview Component on the Document View

15 replies
Last updated: Apr 21, 2020
how do I use a custom preview component on the document view?
Apr 21, 2020, 5:46 PM
say i have an document
that i want to show the video preview on the document view
i also reference this video in another document, but when its a reference, I only want to show the
document title
how is this accomplished?
Apr 21, 2020, 5:47 PM
Just to confirm I’m understanding fully, you have a custom preview component for your
document type, e.g. something like on . You’re happy to show this preview in
, but when you add a reference to the document type you don’t want to see it. Is that correct? What kind of preview does the reference currently show?
Apr 21, 2020, 6:05 PM
Apr 21, 2020, 6:12 PM
here's some screens
Apr 21, 2020, 6:12 PM
Video document... would like the preview here
Apr 21, 2020, 6:13 PM
When referenced ... this is fine
Apr 21, 2020, 6:13 PM
the reason the reference looks ok, is because I removed the
from the schema, otherwise it was trying to load the videoPreview component
Apr 21, 2020, 6:14 PM
Thanks for the shots, always helps! 🙂 Have you considered adding a video object to your video document (under a different name)? That should let you show the preview on the document but just the title in the reference 📽️
This would require loading the preview component in the object instead.
Apr 21, 2020, 6:53 PM
i had not considered that ... so making a
object that goes inside the
document. does the object only contain the URL for the video? (i'm sourcing from vimeo)
Apr 21, 2020, 7:50 PM
Yep, I’d say so, unless you want to add more data that specifically belongs to the video like a title or caption etc.
Apr 21, 2020, 7:54 PM
well, i would think i could just use the
title... since the document is really about the video
Apr 21, 2020, 7:55 PM
One thing you could consider is whether you need that kind of data in the document where you reference the video.
Apr 21, 2020, 8:05 PM
been thinking the same thing ...
Apr 21, 2020, 8:06 PM
99% of the time, i'm probably also the document editor, and i'll know the video already
Apr 21, 2020, 8:06 PM
however, i do see a scenario down the road where I use this dataset as a source for another Sanity project, and the people using that project will need a visual reference to what the video looks like
Apr 21, 2020, 8:07 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern content platform that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing