You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/components/MemoContent/MermaidBlock.tsx

33 lines
790 B
TypeScript

import { useEffect, useRef } from "react";
interface Props {
content: string;
}
const MermaidBlock: React.FC<Props> = ({ content }: Props) => {
const mermaidDockBlock = useRef<null>(null);
useEffect(() => {
// Dynamically import mermaid to ensure compatibility with Vite
const initializeMermaid = async () => {
const mermaid = (await import("mermaid")).default;
mermaid.initialize({ startOnLoad: false, theme: "default" });
if (mermaidDockBlock.current) {
mermaid.run({
nodes: [mermaidDockBlock.current],
});
}
};
initializeMermaid();
}, [content]);
return (
<pre ref={mermaidDockBlock} className="w-full p-2 whitespace-pre-wrap relative">
{content}
</pre>
);
};
export default MermaidBlock;