How to pass field values from schema into custom Studio component?

12 replies
Last updated: Jan 28, 2026
I’ve got a custom component loaded into Studio. It belongs to a post schema. I’m have trouble figuring out how to pass data from the other fields into it. For example I might want to utilize the values of title, except, and body, in it. It’s essentially a hidden form from which I’m going to build a json structure to fire off to the outside world.
AI Update

Perfect! The useFormValue hook is exactly what you need to access values from other fields in your custom component. Here's how to do it:

import { useFormValue } from 'sanity'

const MyCustomComponent = (props) => {
  // Access individual fields from your post schema
  const title = useFormValue(['title'])
  const excerpt = useFormValue(['excerpt'])
  const body = useFormValue(['body'])
  
  // Or get the entire document at once
  const entireDocument = useFormValue([])
  
  // Build your JSON structure
  const jsonStructure = {
    title: title,
    excerpt: excerpt,
    body: body,
    // ... other fields you need
  }
  
  // Your logic to fire off to external world
  const handleSubmit = () => {
    // Send jsonStructure wherever you need
  }
  
  return (
    // Your hidden form UI
  )
}

The key points:

Path syntax: Pass an array to useFormValue with the field name(s):

  • useFormValue(['title']) - gets the title field
  • useFormValue(['parent', 'child']) - for nested fields
  • useFormValue([]) - gets the entire document

Dynamic updates: The hook automatically re-renders your component when those field values change, so your JSON structure will always reflect the current state of the form.

Context requirement: This only works inside custom input components in the form builder. You can't use it in document actions or outside the Studio form context.

If you migrated from Studio v2, this replaces the old props.document pattern - in v3 you must use the useFormValue hook instead.

For your hidden form use case, you might want to use useFormValue([]) to grab the whole document at once, then extract just the fields you need when building your JSON to send externally. This way you don't need to call the hook multiple times if you're working with many fields.

Show original thread
12 replies

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?