Joint session with Vercel: How to build intelligent storefronts (May 15th)

Sanity custom input component: Preventing list expansion on every render

1 replyLast updated: Nov 30, 2025

I'm building a custom input component for a string where I use
props.renderDefault
and I expand the list in the options, since I expand the list by using:
props.schemaType.options = {...props.schemaType.options, list: [...list, ...myList]}
the list in the field keeps getting bigger, looks like that in each render the list I get is the list after it was already expanded (no the original list from 'options')
How can I fix that?
AI Update

The issue you're experiencing is that you're mutating the props.schemaType.options object directly, which causes the list to accumulate on every render. In React, props should be treated as immutable, and schemaType is a shared object reference that persists across renders.

When you do:

props.schemaType.options = {...props.schemaType.options, list: [...list, ...myList]}

You're modifying the actual schema type object, so each render adds to the already-modified list rather than the original one.

Solution

Create a new local options object instead of mutating the original. Here's how to fix it:

export function CustomStringInput(props: StringInputProps) {
  // Create a new schemaType with expanded options without mutating the original
  const expandedSchemaType = {
    ...props.schemaType,
    options: {
      ...props.schemaType.options,
      list: [...(props.schemaType.options?.list || []), ...myList]
    }
  }

  // Pass the new schemaType to renderDefault
  return props.renderDefault({
    ...props,
    schemaType: expandedSchemaType
  })
}

Key Points

This approach ensures that each render starts with the original props.schemaType.options.list from your schema definition, then adds your custom items on top, rather than continuously appending to an ever-growing list.

Show original thread
1 reply

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