
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, this is definitely possible! While Sanity doesn't natively support passing a function directly to options.list in the schema, there's a well-established pattern using custom input components that gives you exactly what you need.
The approach involves creating a custom input component that dynamically generates the list based on the document's current values. Here's the pattern:
import { StringInputProps } from 'sanity'
import { useFormValue } from 'sanity'
function DynamicListInput(props: StringInputProps) {
const document = useFormValue([]) // Gets the entire document
// Generate your list dynamically based on document values
const dynamicList = generateListFromDocument(document)
// Override the options.list with your dynamic values
props.schemaType.options.list = dynamicList
// Render the default string input with the new list
return props.renderDefault(props)
}
function generateListFromDocument(document: any) {
// Your logic here - for example, referencing array items by _key:
const items = document.myArrayField || []
return items.map(item => ({
title: item.title,
value: item._key
}))
}Then in your schema:
defineField({
name: 'mySelectField',
type: 'string',
components: {
input: DynamicListInput
},
options: {
layout: 'dropdown' // or 'radio'
}
})The useFormValue hook gives you access to the current document state, and props.renderDefault(props) renders the standard string input with your modified options. This pattern works great for:
_key propertiesFor cases where you need async data (like GROQ queries), check out this community schema example that shows how to fetch data within a custom component using useClient and React state.
There's an open feature request (#4095) for native function support in options.list, which would make this more straightforward. The custom component approach is currently the recommended solution and works well in production, though it requires a bit more setup than a simple function would.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store