Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Using async `client.fetch` in a custom preview component to expand references and display data from each document.

2 replies
Last updated: Jan 19, 2024
Hi,is it possible to use async
client.fetch
in a custom preview component?What I need is to expand the reference A and then expand the array of references to B. And I need the data from each B document to display in the preview for the object that contains A element
Jan 19, 2024, 1:42 PM
Answering to myself:used
client.fetch
inside
useEffect
and added the prop from prepare as a dependency to trigger an update of the preview when it's ready
Jan 19, 2024, 2:09 PM
You can also select the values you need from the reference. Though, if you need a lot of them it’s way less code to just create a component.
Jan 19, 2024, 5:38 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?