useChat
function useChat(): {
messages: Segment[];
send: (text) => void;
isSending: boolean;
clear: () => void;
};Defined in: packages/react/src/hooks/chat/useChat.ts:31
The message list, a send fn, and isSending for the current <VoiceRoom>.
send forwards to agent.sendText; messages are the transcript segments.
Returns
messages
messages: Segment[];send
send: (text) => void;Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
void
isSending
isSending: boolean;clear
clear: () => void;Clear the transcript + abandon any in-flight turn. No-op if the agent can't reset.
Returns
void
Example
// Basic — send a single chat message.
const { messages, send } = useChat();
<button onClick={() => send("hello")}>Send</button>;
// Advanced — render transcript messages and disable send while busy.
function ChatPanel() {
const { messages, send, isSending } = useChat();
return (
<VoiceRoom agent={agent}>
{messages.map((msg) => <p key={msg.id}>{msg.text}</p>)}
<button disabled={isSending} onClick={() => send("Hello!")}>Send</button>
<RoomAudioRenderer />
</VoiceRoom>
);
}