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

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– 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?