🗓️ Everything *[NYC] is back. A free gathering for AI builders. Sept 9 →

retrieve the values of sibling fields to use in rendering an inputComponent

3 repliesLast updated: Nov 29, 2025

How can I retrieve the values of sibling fields to use in rendering an inputComponent? For example I want to render the text value but with the font specified in the fontSize sibling field.
AI Update

You can access sibling field values in a custom input component using the useFormValue hook from Sanity Studio. This lets you read values from other fields in the same document and use them to customize how your component renders.

Here's how to implement your specific example of rendering text with a font size from a sibling field:

import { useFormValue } from 'sanity'

const CustomTextInput = (props) => {
  // Access the sibling fontSize field
  const fontSize = useFormValue(['fontSize'])
  
  return (
    <div>
      <input
        {...props.inputProps}
        style={{ fontSize: fontSize || '16px' }}
        value={props.value || ''}
        onChange={(e) => props.onChange(e.target.value)}
      />
    </div>
  )
}

export default CustomTextInput

How it works

The useFormValue hook accepts a path array that specifies which field to access:

The hook automatically re-renders your component when the referenced field changes, so your text input will dynamically update its styling as the user modifies the fontSize field.

Common patterns

Multiple sibling fields:

const fontSize = useFormValue(['fontSize'])
const fontWeight = useFormValue(['fontWeight'])
const color = useFormValue(['color'])

// Apply all styles
<input style={{ fontSize, fontWeight, color }} />

Conditional rendering based on sibling:

const showAdvanced = useFormValue(['showAdvancedOptions'])

return showAdvanced ? <AdvancedInput {...props} /> : <SimpleInput {...props} />

Working with array items: When your input is inside an array, you can access other fields in the same array item using the path:

const { path } = props
const parentPath = path.slice(0, -1)
const siblingValue = useFormValue([...parentPath, 'siblingFieldName'])

Important notes

This approach gives you full control over creating dynamic, interdependent form experiences without needing to make API calls or manage complex state yourself.

Show original thread
3 replies

Was this answer helpful?

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.

Related contributions