I'll create a React component that allows users to input Mermaid code and renders it visually. This component will be compatible with Next.js 15 and will use the latest features. Here's how we can implement this:
This implementation creates a MermaidRenderer component that:
The MermaidPage is a simple Server Component that includes the MermaidRenderer. This setup allows for efficient rendering, with the server handling the initial page load and the client managing the interactive Mermaid rendering 3.
To use this in your project:
Install the necessary dependencies:
npm install mermaid @types/mermaidMermaidRenderer.tsx file in your components directory.page.tsx file in the app/mermaid directory to create a /mermaid route in your Next.js application.This implementation takes advantage of Next.js 15's features, such as the App Router and the ability to mix Server and Client Components efficiently 4. The Mermaid rendering itself happens on the client-side, as it requires browser APIs.
Remember to style your components as needed and adjust the layout to fit your application's design. The provided code uses some basic Tailwind CSS classes for layout and styling, assuming you're using Tailwind in your project.
Sources