Use next-mdx-remote with React Server Components (RSC)
mainTo use next-mdx-remote within the Next.js app directory or any React Server Component environment, import from next-mdx-remote/rsc.
Key differences in RSC mode:
<MDXRemote />is an async component and must be rendered on the server.- Use the
sourceprop to pass the MDX string directly (the separate serialization step is no longer required). - The
lazyprop is not supported because rendering occurs on the server. - Custom components must be passed via the
componentsprop. TheMDXProvidercontext from@mdx-js/reactis not supported because RSC does not support React Context. - Client components can be included within the MDX markup.
import { MDXRemote } from 'next-mdx-remote/rsc'
// app/page.js
export default function Home() {
return (
<MDXRemote
source={`# Hello World
This is from Server Components!`}
/>
)
}