Skip to content
Agent UI
Compose primitivesuseCompose

useCompose

Read and drive compose state from any child of ComposeProvider.

useCompose ships with a full API table, a copyable example, and accessibility notes.

tsx

Draft: 0 characters · empty

Installation

Install the package once, then import useCompose from its direct entry point or from the root.

bash
pnpm add @agent-ui/react
tsx
import { useCompose } from "@agent-ui/react";

Tailwind CSS v4 users: add @source "../node_modules/@agent-ui/react/src" to the global stylesheet so the library utilities are generated.

Usage

The example below is the same code that renders the preview. Copy it, swap in your own handlers, and ship.

tsx
import { useCompose } from "@agent-ui/react";
 
function DraftCount() {
const { text } = useCompose();
return <span>{text.length} characters</span>;
}

API reference

Every prop useCompose accepts, its type, default, and behaviour.

API reference for this component
NameTypeDefaultDescription
textstring—Current draft.
setText(t: string) => void—Draft setter.
send(text?: string) => void—Send the draft or a provided override.
canSendboolean—True when the draft is non-empty and not disabled.
disabledboolean—Stage disabled state.
modelsComposeModelOption[]—Available models.
modelIdstring | null—Selected model id.
setModelId(id: string) => void—Model setter.
togglesRecord<string, boolean>—Tool toggle map.
toggle(key: string) => void—Flip a tool toggle.
Use it with the rest of the library

useCompose composes with MessageList, ChatShell, useChat, and the provider compose blocks. Browse the full reference or see all components in the gallery.

6 lines · copy-ready