@a5omic/flowdown-react
v0.1.2
Published
React wrapper for Flowdown — O(1) streaming markdown renderer
Downloads
262
Maintainers
Readme
flowdown-react
React wrapper for @a5omic/flowdown.
@a5omic/flowdown-react keeps Flowdown's incremental parser path while still rendering the unfinished trailing line during React updates.
Install
npm install react react-dom @a5omic/flowdown @a5omic/flowdown-reactComponent
import { StreamMarkdown } from '@a5omic/flowdown-react'
export function ChatMessage({ content }: { content: string }) {
return <StreamMarkdown content={content} />
}Hook
import { useEffect } from 'react'
import { useStreamMarkdown } from '@a5omic/flowdown-react'
export function LiveMessage({ chunks }: { chunks: string[] }) {
const { ref, push, flush, end } = useStreamMarkdown()
useEffect(() => {
for (const chunk of chunks) {
push(chunk)
flush()
}
end()
}, [chunks, push, flush, end])
return <div ref={ref} />
}API
StreamMarkdown
Props:
content: string— Full markdown content received so farclassName?: stringstyle?: CSSPropertieshighlight?: (code, lang) => string | Promise<string>onCodeBlock?: (code, lang) => voidsanitize?: booleanvirtualize?: boolean
useStreamMarkdown(options?)
Returns:
ref— Attach to the container elementpush(chunk)— Append new markdown contentflush()— Materialize the unfinished trailing line without ending the streamend()— Finalize the current streamreset()— Clear all output and parser state
License
MIT
