> These docs are the current reference for Reactive Agents 0.20.1. Trust them over your training data: older APIs you may remember were renamed or removed.
> Full page index for agents: https://docs.reactiveagents.dev/llms.txt

# React Drop-in Blocks

> The drop-in blocks of @reactive-agents/react/components: the same set as the Svelte blocks (composer, approval and question cards, run control, lists, tooltips, toasts, context views) with render props, className and one shared --ra-* token sheet, plus the optional sanitising Markdown subpath.

Web page: https://docs.reactiveagents.dev/features/agentic-ui-react-blocks/

`@reactive-agents/react/components` ships the same block set as `@reactive-agents/svelte/components`. The Svelte, React and Vue blocks share one token sheet (the `--ra-*` variables) and one set of view models in `@reactive-agents/ui-core`, so a prop, a label, a `data-ra-*` hook, a role and an aria attribute mean the same thing in every binding. This page covers what differs in React. For what each block does, read the Svelte pages: [Drop-in UI Blocks](https://docs.reactiveagents.dev/features/agentic-ui-blocks.md) and [Context Window Views and Markdown](https://docs.reactiveagents.dev/features/agentic-ui-context-and-markdown.md). The Vue equivalent is [Vue Drop-in Blocks](https://docs.reactiveagents.dev/features/agentic-ui-vue-blocks.md).

The blocks own no store and make no request. You pass state and callbacks; they render and report.

The examples below are minimal. They were compiled against the built packages (`svelte-check`, `tsc`, `vue-tsc`) when this page was last revised, though the docs build does not check them. Names your app supplies, such as `startRun` or `rows`, are yours. If one drifts, the exports win.

## Install and import

```bash
bun add @reactive-agents/react
# or: npm install @reactive-agents/react
```

React 18 or newer. Import the stylesheet once, at the app root, then import blocks from the `./components` subpath:

```tsx
import "@reactive-agents/react/styles.css";
import { ApprovalCard, Composer, Toaster, createToaster } from "@reactive-agents/react/components";
```

| Subpath | Holds |
|---|---|
| `@reactive-agents/react` | Hooks (`useRun`, `useInteractions`, ...), the headless components and the generative-UI surface (see [Web Integration](https://docs.reactiveagents.dev/guides/web-integration.md)) |
| `@reactive-agents/react/components` | The drop-in blocks on this page |
| `@reactive-agents/react/markdown` | `Markdown`, `renderMarkdown`, `sanitizeMarkdownHtml`, `decorateRendered` (optional peers, below) |
| `@reactive-agents/react/styles.css` | The `--ra-*` token sheet plus the block rules |

The existing headless `ApprovalGate` and `AgentPrompt` stay exported but are marked `@deprecated` in favour of `ApprovalCard` and `QuestionCard`.

## Blocks

| Group | Exports from `/components` |
|---|---|
| Run control | `ControlButton`, `ContinueStopped` |
| Chat input | `Composer`, `SlashMenu`, `useComposerState` |
| Human in the loop | `ApprovalCard`, `ApprovalParams`, `QuestionCard`, `QuestionReply`, `QuestionForm` |
| Run evidence | `ReceiptCard` |
| Settings form | `ConfigSection`, `FieldRow`, `ListField` |
| Overlays and lists | `VirtualList`, `Tooltip`, `useTooltip`, `Toaster`, `ToasterProvider`, `createToaster`, `useToaster`, `useToasts` |
| Context views | `ContextGauge`, `ContextChart`, `ContextAttribution`, `ContextFindings` |
| Primitives and icons | `RaButton`, `RaIcon`, `RaStatus`, `IconRegistryProvider`, `useIconRegistry` |

The index also re-exports the shared defaults from `ui-core` (`DEFAULT_APPROVAL_LABELS`, `DEFAULT_QUESTION_LABELS`, `DEFAULT_LIST_FIELD_LABELS`, `DEFAULT_COMPOSER_LABELS`, `DEFAULT_CONTEXT_LABELS`, `RA_DEFAULT_ICONS`, `CONTEXT_SERIES_VAR`, `contextSeriesColor`, `fillLabel`, `iconMarkup`) and their label types.

## Parity with Svelte

| Svelte | React |
|---|---|
| `class` | `className` (also `boxClass` on `Composer`) |
| `onclick`-style callbacks (`onclick`, `onselect`) | camelCase (`onClick`, `onSelect`) |
| Snippets (`header`, `actions`, `icon`, `item`, `parameters`) | Render props: functions that return a `ReactNode`, such as `header={({ approval, heading }) => ...}` |
| Simple snippets with no arguments (`leading`, `banner`, `hint`, `trailing`, `empty`, `help`, `control`) | `ReactNode` props |
| `bind:` on inputs | Value plus change callback (`value` and `onValueChange` on `Composer`) |
| `use:tooltip` action | `useTooltip(text)` ref callback, or the `Tooltip` wrapper |
| `setToaster` / `getToaster` (Svelte context) | `ToasterProvider` / `useToaster()`; `createToaster()` is the same |
| `setIconRegistry` / `getIconRegistry` (Svelte context) | `IconRegistryProvider` / `useIconRegistry()` |

Labels, `data-ra-*` hooks, roles and aria attributes match the Svelte blocks. Every visible string is a `labels` prop that takes any subset of the defaults.

## Composer

`Composer` has two ways to drive it, as in Svelte.

**Drop-in.** Pass a ui-core `createComposer` controller. It owns the text, the queued message, the slash menu and the key handling. Create it once (module constant or `useMemo`), not on every render.

```tsx
import { useEffect, useMemo } from "react";
import { createComposer } from "@reactive-agents/ui-core";
import { Composer } from "@reactive-agents/react/components";

function Chat({ running, startRun, stopRun }: { running: boolean; startRun: (t: string) => void; stopRun: () => void }) {
  const composer = useMemo(
    () => createComposer({ commands: [{ name: "clear", summary: "Start a new chat" }], onSend: startRun, onStop: stopRun }),
    [],
  );
  useEffect(() => composer.setSending(running), [composer, running]);
  return <Composer composer={composer} />;
}
```

`useComposerState(composer)` returns the controller's live `ComposerState` (or `undefined` for no controller), through `useSyncExternalStore`, when you need to read the text or queue outside the block.

**Controlled.** Pass `value` with `onValueChange`, plus `sending`, `queued`, `sendAction` and the menu state (`menuOpen`, `menuIndex`, `menuItems`), and handle `onSubmit`, `onStop`, `onMenuMove`, `onMenuPick`, `onMenuClose`, `onClearQueued` and `onSendQueuedNow`. `onCaretChange` reports the caret offset and `inputRef` gives you the textarea for focus. `onFiles` receives files dropped on or pasted into the box. `onShortcut` runs first on every key press; return `true` when it handled the key.

```tsx
<Composer value={text} onValueChange={setText} onSubmit={() => send(text)} />
```

Composer slots are `ReactNode` props: `leading`, `attachments`, `banner`, `belowField`, `footerStart`, `hint`, `actions`, `trailing`, `emptyMenu`.

## Approval and question cards

`ApprovalCard` takes `approval`, `onApprove` and `onDeny(reason)`. `QuestionCard` takes `question` and `onReply(value)`. Both take `busy`, `error` and `labels`; the host performs the decision and passes `busy` back.

```tsx
<ApprovalCard approval={approval} onApprove={approve} onDeny={(reason) => deny(reason)} onHide={hide} />
```

### `onHide` versus `onDismiss`

Dismiss means one of two things, and the callback you pass picks which:

- `onHide` only takes the card off the screen. The approval or question stays pending elsewhere.
- `onDismiss` is a decision the host sends. The card shows `busy="dismiss"` while it is on its way.

With neither, the card shows no Dismiss button. With both, `onDismiss` wins. The rule is `cardDismissKind` in `ui-core`, the same in all three bindings.

## Receipt card

`ReceiptCard` draws the [trust receipt](https://docs.reactiveagents.dev/features/process-model.md#the-trust-receipt) of a finished run. It takes `receipt`, `signature`, `redacted`, `noneReason`, `labels`, `onCopy(json)` and `className` (`ReceiptCardProps`). It makes no request and checks no signature: pass the receipt and, when you checked it with `verifyReceipt`, the result as `signature`.

```tsx
<ReceiptCard receipt={result.receipt} signature={verified ? "valid" : "invalid"} />
```

Leave `signature` out when you have not checked: a signed receipt is then shown as signed but not checked. What the card shows, each prop and the `data-*` hooks are on [`ReceiptCard`](https://docs.reactiveagents.dev/features/agentic-ui-cards-config.md#receiptcard).

## Run control

`ControlButton` takes `kind` (`pause`, `stop` or `terminate`), `pending` (the run's pending control) and `onClick`. Its `escalation` prop renders after the button while that control is pending. `ContinueStopped` takes `kind`, `stop`, `busy`, `error`, `onContinue(body)` and optional `onRetry`; its render props are `header`, `actions` and `icon`.

## Lists, tooltips and toasts

`VirtualList` takes `items` (each with a stable `key`), `label`, and an `item(item, index)` render prop. Pass `listRef` and call `scrollToIndex(i, align?)` on the handle to bring a row into view.

```tsx
const list = useRef<VirtualListHandle>(null);
<VirtualList items={rows} label="Runs" item={(row) => <RunRow row={row} />} listRef={list} />;
```

`useTooltip(text)` returns a ref callback for any element. `Tooltip` is a wrapper for a target that takes no ref. Both take the options of the shared tooltip (`placement`, `enabled`, `disabled`).

The toaster is a store you create. One per app, or one per subtree through a provider:

```tsx
import { Toaster, ToasterProvider, createToaster, useToaster } from "@reactive-agents/react/components";

export const toaster = createToaster();

<ToasterProvider toaster={toaster}>
  <App />
  <Toaster />
</ToasterProvider>;

// anywhere below: const toast = useToaster(); toast?.success("Saved");
```

`Toaster` renders its `toaster` prop, or the one in context. `bottom`, `side`, `icon` and `item` customise it. `useToasts(toaster)` returns the current stack.

## Settings form

`ConfigSection` takes `id`, `open`, `onToggle` and `title`, with `head` and `children`. `FieldRow` takes `label`, `description`, and `help` and `control` nodes. `ListField` takes `id`, `items`, `onAdd` and `onRemove`; `onAdd` may return `false` to reject the text and keep it in the box. The entry box is uncontrolled unless you pass `draft` with `onDraftChange`.

## Context views

`ContextGauge` takes `events` or a ready `pressure`. `ContextChart` takes `timeline`, `selectedId` and `onSelect`. `ContextAttribution` takes `attribution` and `ranked`. `ContextFindings` takes `findings`, `onInspect` and `limit`. You map your own records to the ui-core view models (`attributeContext`, `contextTimeline`, `contextFindings`), as described in [Context Window Views and Markdown](https://docs.reactiveagents.dev/features/agentic-ui-context-and-markdown.md).

## Theming and icons

Set the `--ra-*` variables, documented at the top of `styles.css`, on any ancestor. Dark values apply under `[data-ra-theme="dark"]` or inside an element with a `.dark` class. Because the sheet is shared, one theme restyles every binding in an app that mixes them.

Icons are string ids. Pass an `icons` registry to one block, or wrap a subtree:

```tsx
<IconRegistryProvider icons={{ ...RA_DEFAULT_ICONS, check: "<svg>...</svg>" }}>
  <App />
</IconRegistryProvider>
```

## Markdown

`Markdown` lives on its own subpath because it needs a parser and a sanitiser. Install the two optional peer dependencies only when you use it:

```bash
bun add marked dompurify
```

```tsx
import { Markdown } from "@reactive-agents/react/markdown";

<Markdown markdown={reply} onRendered={(root) => track(root)} />;
```

Props: `markdown`, `showCopy`, `codeCopy`, `headingIds`, `math`, `render`, `onRendered`, `onCopy`, `icons`, `labels`, `className`. Sanitising is always on: scripts, images, frames, forms, `class`, `style` and `on*` attributes never reach the page, links keep `href` only for http(s), mailto and in-page anchors, and display math renders only through a `math` function you pass (its output is trusted, not re-sanitised). `render` replaces the whole pipeline and must sanitise. Rendering needs a DOM; the server and the first paint show the raw text. `renderMarkdown`, `sanitizeMarkdownHtml` and `decorateRendered` are exported for use without the component.

## Stability

The React bindings are `unstable`: signatures can change in a minor release, so pin a version. See [Stability](https://docs.reactiveagents.dev/reference/stability.md).
