
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeBased on your question, it sounds like you have custom block types called hero and content in your Portable Text schema, and you want to define how they render as JSX elements in your React components.
Here's how you can define custom block types as JSX elements using the @portabletext/react library:
import { PortableText } from '@portabletext/react'
// Define your custom components
const HeroComponent = ({ value }) => {
return (
<div className="hero">
<h1>{value.title}</h1>
<p>{value.description}</p>
{/* Access other fields from your hero block */}
</div>
)
}
const ContentComponent = ({ value }) => {
return (
<section className="content-section">
{/* Render whatever fields your content block has */}
<div>{value.body}</div>
</section>
)
}
// Define the components object
const ptComponents = {
types: {
hero: HeroComponent,
content: ContentComponent,
// Add other custom block types here
}
}
// Use it in your render
function MyPage({ portableTextData }) {
return (
<PortableText
value={portableTextData}
components={ptComponents}
/>
)
}The key points from the Portable Text documentation:
value prop (not node - that's the old API) containing all the data from your blocktypes object within the components propIf you're getting an "Unknown block type" error, make sure:
components.types object match exactly what you defined in your Sanity schemaYou can also check out this comprehensive guide on customizing Portable Text which covers the full flow from schema definition to React rendering.
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