The running React example uses React 19
and a resolved map. Install its development dependencies with
npm install --prefix examples/frameworks/react, then run
npm run dev --prefix examples/frameworks/react. The example keeps all React
packages outside the published library.
Import the element registration and stylesheet once. A URL goes in src;
React 19 passes a JavaScript object to the custom element's map property:
import "@metronforge/concept-map/element";
import "@metronforge/concept-map/css";
import map from "./map.json";
function Map({ input }) {
if (input === "url") return <concept-map src="/map.json" />;
return <concept-map map={map} />;
}The example component lets you switch between both inputs and hide the map. React removes the element on unmount; the element then destroys its player and stops pending work. Use a resolved map as shown here. A source map needs a layout engine; see automatic layout.
For server rendering, renderFigure produces the initial figure inside the
custom element. The server script
uses React's renderToString; importing the element entry in the browser then
connects controls to the existing figure:
import { createElement } from "react";
import { renderToString } from "react-dom/server";
import { renderFigure } from "@metronforge/concept-map";
const html = renderToString(
createElement("concept-map", {
dangerouslySetInnerHTML: { __html: renderFigure(map) },
}),
);The figure HTML comes from the library, which escapes map text and embeds the
map data. Keep the package stylesheet on the page. Run
npm run test:browser --prefix examples/frameworks/react to check both client
inputs, unmount cleanup, and server markup hydration in Chromium.