@json-render/react-email

React Email renderer. Turn JSON specs into HTML or plain-text emails using @react-email/components and @react-email/render.

Install

npm install @json-render/core @json-render/react-email @react-email/components @react-email/render

See the React Email example for a full working example.

schema

The email element schema for specs. Use with defineCatalog from core.

import { defineCatalog } from '@json-render/core';
import { schema, standardComponentDefinitions } from '@json-render/react-email';

const catalog = defineCatalog(schema, {
  components: standardComponentDefinitions,
});

Render Functions

Server-side functions for producing email output. All accept a spec and optional RenderOptions.

import { renderToHtml, renderToPlainText } from '@json-render/react-email';

const html = await renderToHtml(spec);

const plainText = await renderToPlainText(spec);

RenderOptions

interface RenderOptions {
  registry?: ComponentRegistry;
  includeStandard?: boolean;  // default: true
  state?: Record<string, unknown>;
}
OptionDescription
registryCustom component map (merged with standard components)
includeStandardInclude built-in standard components (default: true)
stateInitial state for $state / $cond dynamic prop resolution

defineRegistry

Create a type-safe component registry from a catalog. Components receive { props, children, emit, bindings, loading }.

import { defineRegistry } from '@json-render/react-email';
import { Container, Heading, Text } from '@react-email/components';

const { registry } = defineRegistry(catalog, {
  components: {
    Card: ({ props, children }) => (
      <Container style={{ padding: 16, backgroundColor: '#fff' }}>
        <Heading>{props.title}</Heading>
        {children}
      </Container>
    ),
  },
});

const html = await renderToHtml(spec, { registry });

createRenderer

Create a standalone renderer component wired to state, actions, and validation (for interactive previews in the browser).

import { createRenderer } from '@json-render/react-email';

const EmailRenderer = createRenderer(catalog, components);

Renderer

The main component that renders a spec to React Email elements. Use inside JSONUIProvider when you need state, actions, or visibility.

interface RendererProps {
  spec: Spec | null;
  registry?: ComponentRegistry;
  includeStandard?: boolean;  // default: true
  loading?: boolean;
  fallback?: ComponentRenderer;
}

Standard Components

Document structure

ComponentDescription
HtmlTop-level email wrapper. Must be the root element.
HeadEmail head section. Place inside Html.
BodyEmail body wrapper. Place inside Html.

Layout

ComponentDescription
ContainerConstrains content width (e.g. max-width 600px).
SectionGroups related content.
RowHorizontal layout row.
ColumnColumn within a Row.

Content

ComponentDescription
HeadingHeading text (h1-h6).
TextBody text paragraph.
LinkHyperlink with text and href.
ButtonCall-to-action button (link styled as button).
ImageImage from URL.
HrHorizontal rule separator.

Utility

ComponentDescription
PreviewPreview text for inbox (inside Html).
MarkdownRenders markdown content as email-safe HTML.

Server-Safe Import

Import schema and catalog definitions without pulling in React or @react-email/components:

import { schema, standardComponentDefinitions } from '@json-render/react-email/server';

Sub-path Exports

ExportDescription
@json-render/react-emailFull package: schema, renderer, components, render functions
@json-render/react-email/serverSchema and catalog definitions only (no React)
@json-render/react-email/catalogStandard component definitions and types
@json-render/react-email/renderServer-side render functions only

Types

ExportDescription
ReactEmailSchemaSchema type for email specs
ReactEmailSpecSpec type for email documents
RenderOptionsOptions for render functions
ComponentContextTyped component render function context
ComponentFnComponent render function type
StandardComponentDefinitionsType of the standard component definitions object
StandardComponentProps<K>Inferred props type for a standard component by name