Overview
TheuseTambo() hook is the primary hook for accessing Tambo functionality. It combines thread state, streaming status, component registry, and client access into a single convenient interface.
Messages returned from this hook include a renderedComponent property on component content blocks, allowing direct rendering in your UI.
Import
Usage
Return Value
Thread State
Current thread state for the active thread, or
undefined if not loaded.Current thread ID (always available - uses “placeholder” for new threads before creation).
Messages in the current thread. Component content blocks include
renderedComponent for direct rendering:Streaming State
Current streaming state object with detailed status information.
Whether the thread is currently streaming a response from the AI.
Whether the thread is waiting for the AI to start responding.
Whether the thread is idle (not streaming or waiting).
Client & Registry
The Tambo API client instance for direct API access.
Map of registered components (name → component definition).
Map of registered tools (name → tool definition).
Function to register a component with the registry at runtime.
Function to register a tool with the registry at runtime.
Function to register multiple tools with the registry at runtime.
Thread Management
Initialize a thread in the stream context. Use this to prepare a thread for receiving events.
Switch to an existing thread. Updates the current thread context.
Start a new thread. Generates a temporary placeholder ID until the thread is created server-side.
Update a thread’s name. Useful for implementing manual thread renaming UI.Cache invalidation is best-effort; failures will be logged and won’t reject the promise.
Cancel the current run on this thread. Optimistically updates local state and sends cancellation request to the API.No-op if there’s no active run or thread is a placeholder.
Authentication
Current authentication state. Use this to show auth-related UI or conditionally render features.Possible states:
{ status: "unauthenticated" }- No auth configured{ status: "invalid" }- Both userKey and userToken provided{ status: "identified", userKey: string }- Ready to make API calls{ status: "error", error: Error }- Token exchange failed
Shorthand for
authState.status === "identified". When true, the SDK is ready to make API calls.Advanced
Dispatch function for stream events. Advanced usage only - use for custom stream event handling.
Type Definitions
UseTamboReturn
ReactTamboThreadMessage
Examples
Basic Message Display
Thread Switching
Canceling a Run
Dynamic Component Registration
Related
- useTamboThreadInput() - Manage message input
- useTamboComponentState() - Component state management
- useTamboStreamStatus() - Granular streaming status