Joy DOM

Overview

Install and embed the @joy-dom/react renderer in a React 19 app.

@joy-dom/react renders a Joy DOM JSON document into React elements. It powers the live previews on the spec page.

Install

npm install @joy-dom/react @joy-dom/core

The install is two packages:

  • @joy-dom/react is the renderer. It lists react and react-dom 19 as peer dependencies, so add those to your app if they are not there yet.
  • @joy-dom/core holds the TypeScript types and JSON Schema for the document format. It types your specs.

First render

import {  } from "@joy-dom/react";
import type {  } from "@joy-dom/core";

const :  = {
  : 1,
  : {
    ".hello": { : "flex", : { : 16, : "px" } },
    : { : "flex" },
  },
  : [],
  : {
    : "div",
    : { : ["hello"] },
    : [{ : "p", : ["Hello Joy DOM"] }],
  },
};

export function () {
  return < ={} />;
}

<Joy> drops in anywhere a React component goes. It renders the document into its own shadow root, so the spec's global ids and classes stay isolated from the host page.

Where next

On this page