✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Display all the tags (and their category) of a single recipe.

1 replies
Last updated: Feb 10, 2021
My project is a recipe-app in React and I want to display all the tags (and their category) of a single recipe.I just can’t figure out how to write the schema’s.
When I inspect the document of the recipe, I only get _key and _ref.
What did I do wrong?
Feb 10, 2021, 2:03 PM
Hi Pieter, this is correct - the
_key
is to give each array item a unique identifier and the
_ref
is the ID of the referenced document. To show these references in your React app, you will need to use the dereferencing operator
->
to join them in your query.
For example, if you're using GROQ:

*[_type == "recipe"]{
  ...,
  thetags[]->{
    ...,
    category->
  }
}
Feb 10, 2021, 2:22 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?