Discussion on async schemas and validation functions in Sanity.io
Based on the context of your question, I believe you're asking whether the list property on a string field (which defines dropdown/select options) can be a promise or async function.
No, the list property cannot be a promise. The list property in Sanity schema definitions must be either:
- An array of strings or objects:
defineField({
name: 'category',
type: 'string',
options: {
list: ['news', 'blog', 'tutorial']
// or
// list: [
// {title: 'News', value: 'news'},
// {title: 'Blog', value: 'blog'}
// ]
}
})- A synchronous function that returns an array:
defineField({
name: 'category',
type: 'string',
options: {
list: () => ['news', 'blog', 'tutorial']
}
})The schema definition in Sanity is evaluated synchronously when Studio loads, so promises and async functions aren't supported in the list property.
Workarounds for dynamic options:
If you need to load options dynamically from an API or database, you have a few alternatives:
- Create a separate document type for your options and use a
referencefield instead of a string list - Use a custom input component that fetches options asynchronously and renders them as a dropdown
- Pre-populate options during your build/deploy process and include them in your schema definition
The custom input component approach gives you the most flexibility - you can fetch data when the component mounts and present it to users while still storing the value as a string field.
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.