Issue with Sanity UI Autocomplete component custom rendering
I can see you're hitting the "Constructor requires 'new' operator" error with the Sanity UI Autocomplete component when using custom rendering. While I couldn't locate specific documentation about this exact error in the Sanity UI docs, this error typically occurs in React when there's a component instantiation issue.
Here are the most common causes and solutions to try:
1. Check for React version conflicts
This error often happens when you have multiple versions of React in your project. Check what's installed:
npm ls reactIf you see multiple versions, you'll need to deduplicate them. Sanity UI requires React 18+ as a peer dependency, so ensure you're using compatible versions.
2. Verify your component definition
Make sure your custom rendering component is properly defined as a React component:
import {Autocomplete, Card, Text} from '@sanity/ui'
// Define as a proper function component
function CustomOptionRenderer({children}) {
return (
<Card padding={3}>
<Text>{children}</Text>
</Card>
)
}
// Use it in renderOption
<Autocomplete
options={[
{value: 'option1'},
{value: 'option2'}
]}
renderOption={(option) => (
<CustomOptionRenderer>
{option.value}
</CustomOptionRenderer>
)}
/>3. Try inline rendering first
To isolate whether the issue is with your custom component or the Autocomplete itself:
<Autocomplete
options={[
{value: 'option1'},
{value: 'option2'}
]}
renderOption={(option) => (
<Card padding={3}>
<Text>{option.value}</Text>
</Card>
)}
/>If this works but a separate component doesn't, the issue is with how your component is defined or exported.
4. Avoid HTML element names
Don't name your components after native HTML elements like Option, Select, or Input. React may try to instantiate them as DOM elements, causing this error. Use names like CustomOption or AutocompleteOption instead.
5. Check styled-components compatibility
Since Sanity UI uses styled-components as a peer dependency, verify you have a compatible version:
npm ls styled-components6. Clear build cache
Sometimes stale build artifacts cause this:
rm -rf node_modules package-lock.json
npm install7. Check the full error stack
Look at your browser console for the complete error stack trace. It should indicate which specific component or line is causing the issue, which can help narrow down the problem.
If none of these solutions work, it would help to see your actual implementation code and the versions of @sanity/ui, react, and styled-components you're using. The full error stack trace would also provide valuable debugging information.
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.