GitHubX

Markdown Content

PreviousNext

A component that renders markdown content.

This component provides a simple way to render Markdown content with optimized performance through memoization. The implementation uses memoized blocks which prevents unnecessary re-renders and improves rendering efficiency, especially when dealing with streaming content.

The memoization approach is inspired by the Vercel AI SDK's markdown chatbot example. As they explain, memoization caches parsed Markdown blocks and reuses them to avoid redundant parsing and rendering operations. This is particularly beneficial when content is being streamed or updated frequently, as it ensures that only changed blocks are re-rendered rather than the entire content.

Installation

pnpm dlx shadcn@latest add @simple-ai/markdown-content

Usage

import { MarkdownContent } from "@/components/ui/markdown-content"
<MarkdownContent id="my-id" content={content} />

Examples

Streaming

This component supports streaming content with automatic batching