React Hooks
IvyProvider, useIvyJob, and useIvyWebSocket hooks for React integration
The /react subpath lets you drop IvyAI into a React app without wiring the client by hand — a provider supplies the client through Context, and hooks handle job submission and live WebSocket progress for you. Reach for it when you're building React UI (like a dashboard) and want state-aware hooks instead of calling the client methods directly. It wraps the same underlying pieces documented across the other SDK pages, so it sits one layer above them.
SDK React Hooks Reference
Planned specification. @ivybiosciences/sdk is not released, and there is no package to install. This page describes the SDK's planned interface. To call the platform today, use the REST API, the ivybloom CLI, or the MCP server.
The @ivybiosciences/sdk/react subpath provides React hooks for integrating IvyAI into React applications. Includes context management, job submission, and WebSocket subscriptions.
React 18+ is a peer dependency — it's only required if you import from the
/reactsubpath.
IvyProvider
Provides an IvyClient instance to the component tree via React Context. All hooks require a parent <IvyProvider>.
The client is memoized — it's only re-created when config.apiKey or config.baseUrl change.
Examples
useIvyClient()
Access the IvyClient instance from context.
Throws: Error if called outside of an <IvyProvider>.
Example
useIvyJob(options?)
Submit and track computational jobs with real-time progress updates.
Combines job submission with real-time progress tracking. Handles WebSocket subscription, polling fallback, error states, and cleanup on unmount.
Lifecycle
- Call
submit(toolName, params)to start a job isLoadingbecomestrue,statusupdates in real-time- On completion:
onCompletefires,isLoadingbecomesfalse - On error:
onErrorfires,erroris populated
Options
| Field | Type | Default | Description |
|---|---|---|---|
onProgress | (progress: JobProgress) => void | — | Called on each status/progress change |
onComplete | (result: JobProgress) => void | — | Called when job reaches COMPLETED status |
onError | (error: Error) => void | — | Called on submission or runtime failures |
useWebSocket | boolean | true | Use WebSocket for real-time updates |
pollInterval | number | 3000 | Polling interval in ms (fallback mode) |
Return Value
| Field | Type | Description |
|---|---|---|
submit | (toolName, parameters, opts?) => Promise<string> | Submit a job and begin tracking |
status | JobProgress | null | Current progress snapshot |
isLoading | boolean | Whether a job is in progress |
error | Error | null | Last error encountered |
cancel | () => void | Cancel tracking (not server-side computation) |
Examples
useIvyWebSocket(jobId, options?)
Subscribe to real-time WebSocket updates for a specific job. Use this when you need fine-grained control over WebSocket subscriptions. For most use cases, useIvyJob (which uses WebSocket internally) is simpler.
Manages the full WebSocket lifecycle declaratively:
- Connects when
jobIdis provided andenabledis true - Disconnects and cleans up on unmount or when
jobIdchanges - Provides reactive state for progress, connection status, and errors
Options
Extends WebSocketOptions with:
| Field | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Whether to establish the connection |
autoReconnect | boolean | true | Reconnect on unexpected close |
maxReconnectAttempts | number | 5 | Max reconnection attempts |
reconnectInterval | number | 1000 | Base delay in ms (doubles each attempt) |
onReconnect | (attempt: number) => void | — | Called on each reconnection attempt |
onClose | (code: number, reason: string) => void | — | Called when connection closes |
Return Value
| Field | Type | Description |
|---|---|---|
status | JobProgress | null | Latest progress data from WebSocket |
isConnected | boolean | Whether the WebSocket is in OPEN state |
error | Error | null | Connection error, if any |
Examples
Hook Comparison
| Hook | Auth Required | WebSocket | Use Case |
|---|---|---|---|
useIvyJob | Yes | Automatic | Full job lifecycle (submit + track) |
useIvyWebSocket | Yes | Manual | Custom monitoring of existing jobs |
Every hook needs an API key or a Clerk JWT. To try the platform without a key, send the keyless orchestrate request in Guest curl instead.
Full Example: Job Dashboard
Advanced Patterns
Combining Hooks: Multi-Job Monitoring
When you need to track multiple jobs simultaneously, combine useIvyClient for submission with useIvyWebSocket for per-job monitoring.
Why this pattern?
useIvyJobmanages a single job's lifecycle. When monitoring multiple concurrent jobs, usinguseIvyClientfor submission + individualuseIvyWebSocketsubscriptions gives you independent state per job without conflicts.
State Management Integration
Integrating IvyAI hooks with external state managers (Zustand, Redux, etc.) for persistence and cross-component sharing.
Error Recovery with Retry Logic
Build resilient UIs with automatic retry on transient failures.
Best Practices
Provider Placement
Place <IvyProvider> as high as needed, but not higher. If only one route uses IvyAI, wrap just that route:
Handle Loading States Gracefully
Always provide visual feedback during async operations:
Clean Up on Unmount
The hooks handle cleanup automatically, but be aware of the behavior:
useIvyJob: Callscancel()internally on unmount — stops tracking but does not cancel server-side computationuseIvyWebSocket: Closes WebSocket connection on unmount
The SDK has no server-side cancel call. A job keeps running after the component unmounts; delete it with ivy.jobs.delete(jobId) if you no longer want it.
Type Your Results
Define explicit types for job results to get TypeScript benefits:
Was this page helpful?