The document handle for the document you want to resolve preview values for, and an optional ref
The preview values for the given document and a boolean to indicate whether the resolution is pending
// PreviewComponent.jsx
export default function PreviewComponent({ document }) {
const { data: { title, subtitle, media }, isPending } = useDocumentPreview({ document })
return (
<article style={{ opacity: isPending ? 0.5 : 1}}>
{media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}
<h2>{title}</h2>
<p>{subtitle}</p>
</article>
)
}
// DocumentList.jsx
const { data } = useDocuments({ filter: '_type == "movie"' })
return (
<div>
<h1>Movies</h1>
<ul>
{data.map(movie => (
<li key={movie._id}>
<Suspense fallback='Loading…'>
<PreviewComponent document={movie} />
</Suspense>
</li>
))}
</ul>
</div>
)
Returns the preview values of a document (specified via a
DocumentHandle
), including the document’stitle
,subtitle
,media
, andstatus
. These values are live and will update in realtime. To reduce unnecessary network requests for resolving the preview values, an optionalref
can be passed to the hook so that preview resolution will only occur if theref
is intersecting the current viewport.