
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeWhen you add an image to your rich text blog post and see the error Unknown block type "image", specify a component for it in the components.types prop, it means you need to tell the Portable Text renderer how to display images.
Here's how to fix it:
If you're using the modern @portabletext/react library, add an image component to your components configuration:
import {PortableText} from '@portabletext/react'
import imageUrlBuilder from '@sanity/image-url'
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
apiVersion: '2023-05-03',
useCdn: true
})
const builder = imageUrlBuilder(client)
function urlFor(source) {
return builder.image(source)
}
const components = {
types: {
image: ({value}) => {
if (!value?.asset?._ref) {
return null
}
return (
<img
alt={value.alt || ' '}
loading="lazy"
src={urlFor(value).width(800).url()}
/>
)
}
}
}
// Then use it:
<PortableText value={yourContent} components={components} />Install the image URL builder if you haven't already:
npm install @sanity/image-urlThe components.types prop is where you define custom renderers for different block types in your Portable Text
Access image data through value.asset._ref - this is the reference to the image in Sanity
Use imageUrlBuilder to generate optimized image URLs with transformations like width, height, and format
You can customize this further by adding responsive images, different sizes, or styling. The Presenting Portable Text guide has more examples of customizing how different content types render.
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