Custom Studio input implementation issue with useFormValue in Sanity

2 replies
Last updated: Jun 21, 2024
Hello all, I am trying to implement a custom Studio input. I have a document where there is an array of objects, and in this objects there is a reference field and a field with the custom component. The idea is to fetch the referenced document and display a select based on some values of that document. The problem I am having is that with
useFormValue
it does not seems as I can identify which object is being rendered. So the component does not know in which object resides or from which object read the reference field. Keep in mind each object migh have different values in that reference field.
Does someone have any idea on how to overcome this?
Jun 20, 2024, 6:12 PM
Your component will receive a
path
array in your
props
. You can slice the last item off of that array to get the parent object. That will contain your sibling field with the reference.
Jun 20, 2024, 8:31 PM
Thank you. Yes, the path prop does the trick!
Jun 21, 2024, 6:45 AM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?