Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

How to get a reference value of another field within the 'hidden' property in Sanity.io.

3 replies
Last updated: Mar 19, 2024
Hey all, how can i get a reference value of another field within the
property? For example, I want to show/hide a field based on the value of a reference field.
  name: 'industry',
  title: 'Industry',
  type: 'reference',
  to: [{type: 'industries'}],
  name: 'industryCustom',
  title: 'Industry (Custom)',
  type: 'string',
  hidden: ({ parent }) => {
    // need to get value of `industry` field above.
    // `parent` only holds `_ref` but not actual value
Mar 19, 2024, 2:36 PM
The hidden field can’t handle promises, so you won’t be able to get any values from the resolved
reference. You’ll need to use a custom component to get access to the client and conditional rendering to handle it.
Mar 19, 2024, 3:57 PM
gotcha, had a feeling it was headed that way 😂 thanks for the help as always!
Mar 19, 2024, 5:26 PM
You’re welcome 🙂
Mar 19, 2024, 6:33 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?