Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

Is there an easy way to get the reference data in a deeply nested component? I have a list of different components, some of them have arrays of references which I’d liketo...

3 replies
Last updated: Jan 6, 2021

Is there an easy way to get the reference data in a deeply nested component? I have a list of different components, some of them have arrays of references which I’d like to expose. I’ve managed to get one of the components to expose the references, but it overrides the entire array with empty objects for all the other components.

body[]{ links[]-> }
What I need is a
*
to expose the original content, but override certain fields.

Jan 6, 2021, 11:07 AM

not 100% I understand you, and I'm a GROQ newbie myself but have you tried this

body[] {
  ...,
  links[]->
}

Jan 6, 2021, 11:11 AM

Pretty sure youre looking for something like this:

body[] {
  links[]-> {
    "aThing": title,
    ...
  }
}
The triple dot will display all properties of an object within the
links
array,
"aThing": title
assigns the
title
property to
aThing

Jan 6, 2021, 11:11 AM

Thanks! Exactly what I was looking for!

Jan 6, 2021, 11:11 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.