Skip to content

@genga-cms/react

React components for Genga content in the public shape: the blocks of a page, rich text, and the live preview of the editor. Use it with @genga-cms/react-router, or in any React app that reads a PublicDocument.

Package React Node
@genga-cms/react ^19.0 >=22.12

The version of @genga-cms/react is the version of genga.

// app/blocks.ts: the config holds the schemas, the site gives the components.
import { defineBlockComponents } from '@genga-cms/react';
export const blocks = defineBlockComponents(gengaConfig, { hero: Hero, 'rich-text': RichTextSection });
// a block component
import { RichText, type BlockProps } from '@genga-cms/react';
export function RichTextSection({ content }: BlockProps<typeof richTextBlock>) {
return <RichText value={content} />;
}
// a page
const { data } = usePreviewData(doc, preview, { head: (data) => ({ title: String(data.title) }) });
return <Blocks blocks={data.body} registry={blocks} preview={preview} />;
  • defineBlockComponents(config, components) throws on a key that is not a block type of the config. BlockProps<typeof block> types the props of a component.
  • Blocks renders the blocks in order, each in an error boundary. A block type without a component renders nothing on the site, and a notice in a preview.
  • RichText renders the TipTap JSON with the allowlist of Genga, without dangerouslySetInnerHTML.
  • usePreviewData(doc, preview, { adminOrigin, onSaved, head }) connects the page to the editor in a preview, and returns the draft at each change. adminOrigin defaults to the origin of the page (embedded mode).

genga/client and genga/render keep their own RenderBlocks, RichText and usePreviewData until 1.0.