Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created June 13, 2024 12:07
Show Gist options
  • Save kuc-arc-f/1277664a36e3e492ecb939a371bfee83 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/1277664a36e3e492ecb939a371bfee83 to your computer and use it in GitHub Desktop.
Remix + mermaid.js sample
import type { MetaFunction } from "@remix-run/node";
import React, { useEffect, useRef } from 'react';
import mermaid from 'mermaid';
//
type Props = {
src: string;
className?: string;
};
//
export function Mermaid({ src, className }: Props) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (src && ref.current) {
mermaid.init({}, ref.current);
}
}, [ref.current, src]);
return (
<div className={className} ref={ref}>
{src}
</div>
);
}
//
export const meta: MetaFunction = () => {
return [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];
};
//
const src1 = `erDiagram
e01 ||--|{ e02: "1 対 多(1以上)"
e01 ||--o{ e03: "1 対 多(0以上)"
e01 ||--o| e04: "1 対 0か1"
`;
//
export default function Index() {
//
return (
<div>
<h1 className="text-4xl">Test2.tsx!</h1>
<hr />
<button>[ Test ]</button>
<Mermaid src={src1} className={'mermaid1'} />
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment