PortableText content prop error in Next.js after publishing to Sanity

13 replies
Last updated: Nov 29, 2025
I'm struggling with PortableText components content prop in react/next.js. I get this error every time i publish content to the sanity cms editor and try and load the post on my local host.
my nextjs code


<PortableText
            className='mt-10'
            content={post.body}
            dataset={process.env.NEXT_PUBLIC_SANITY_DATASET}
            projectId={process.env.NEXT_PUBLIC_SANITY_PROJECT_ID}
            serializers={{
              h1: (props: any) => (
                <h1 className='text-2xl font-bold my-5'>{props}</h1>
              ),
              h2: (props: any) => (
                <h2 className='text-xl font-bold my-5'>{props}</h2>
              ),
              li: (props: any) => <li className='ml-4 list-disc'>{props}</li>,
              link: ({ href, children }: any) => (
                <a className='text-blue-500 hover:underline' href={href}>
                  {children}
                </a>
              ),
            }}
          />

AI Update

Looking at your code, I can see the issue! You're using the old deprecated @sanity/block-content-to-react package API with serializers and content props, but it looks like you've upgraded to the newer @portabletext/react package which has a different API.

The @sanity/block-content-to-react package was deprecated in favor of @portabletext/react, and the new package uses different prop names:

  • contentvalue
  • serializerscomponents
  • You no longer need dataset and projectId props

Here's how to update your code:

import { PortableText } from '@portabletext/react'

<PortableText
  className='mt-10'
  value={post.body}  // Changed from 'content' to 'value'
  components={{      // Changed from 'serializers' to 'components'
    block: {
      h1: ({children}) => (
        <h1 className='text-2xl font-bold my-5'>{children}</h1>
      ),
      h2: ({children}) => (
        <h2 className='text-xl font-bold my-5'>{children}</h2>
      ),
    },
    list: {
      bullet: ({children}) => <ul className='ml-4'>{children}</ul>,
    },
    listItem: {
      bullet: ({children}) => <li className='list-disc'>{children}</li>,
    },
    marks: {
      link: ({value, children}) => (
        <a className='text-blue-500 hover:underline' href={value?.href}>
          {children}
        </a>
      ),
    },
  }}
/>

Key changes to note:

  1. Props structure: The components receive children instead of being passed the entire props object
  2. Organization: Components are organized into block, list, listItem, and marks categories
  3. Links: Links are now under marks.link and receive a value prop with the link data

Make sure you have @portabletext/react installed:

npm install @portabletext/react

You can find more details in the official Sanity documentation on presenting Portable Text, which covers the migration from the old package to the new one.

Show original thread
13 replies

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.

Was this answer helpful?