
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see your code structure is actually correct according to the official Sanity documentation! The pattern of using icon and component directly on the decorator object is the right approach for Sanity v3. However, there are a few things that might be causing issues. Let me help you troubleshoot:
Your code structure is correct, but here are some common issues and solutions:
Make sure you have React imported at the top of your file since you're using JSX:
import React from 'react'Your icon function should return a proper React element. Try this:
{
title: 'Highlight',
value: 'highlight',
icon: () => <span style={{fontWeight: 'bold'}}>H</span>,
component: (props: any) => (
<span style={{ backgroundColor: 'yellow' }}>{props.children}</span>
),
}Instead of an inline function, you could import an icon from the @sanity/icons package:
import { HighlightIcon } from '@sanity/icons'
// Then in your decorator:
{
title: 'Highlight',
value: 'highlight',
icon: HighlightIcon,
component: (props: any) => (
<span style={{ backgroundColor: 'yellow' }}>{props.children}</span>
),
}Here's a complete working example based on the official documentation:
import React from 'react'
const HighlightIcon = () => (
<span style={{ fontWeight: 'bold' }}>H</span>
)
const HighlightDecorator = (props: any) => (
<span style={{ backgroundColor: 'yellow' }}>{props.children}</span>
)
export default {
title: "Titre du block",
name: "titleBlock",
type: "array",
of: [{
type: "block",
marks: {
decorators: [
{ title: "Strong", value: "strong" },
{ title: "Emphasis", value: "em" },
{ title: "Code", value: "code" },
{ title: "Underline", value: "underline" },
{ title: "Strike", value: "strike-through" },
{
title: 'Highlight',
value: 'highlight',
icon: HighlightIcon,
component: HighlightDecorator,
}
],
}
}],
group: "text",
validation: (Rule: any) => Rule.required(),
}You're absolutely right to use .tsx files! Sanity v3 works perfectly with TypeScript. The documentation examples use .js for simplicity, but .tsx is actually the recommended approach for type safety. This is not causing your issue.
After making schema changes, make sure to restart your Sanity Studio dev server:
npm run devor if you're using the newer commands:
npx sanity devpackage.json for sanity version)npx sanity upgradeWithout seeing the picture you mentioned, the most common issues are:
component prop receives and renders props.childrenThe pattern you're using matches the official documentation exactly, so if it's still not working after these adjustments, please share any error messages from the console and I can help further! 🙏
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