React Client SDK Reference
React hooks and components for integrating Helper into your React applications
React Hooks Reference
The Helper React package provides a collection of React hooks and components that make it easy to integrate Helper's chat capabilities into your React applications. Built on top of the Client SDK, these hooks provide reactive state management using React Query.
Installation
bash npm install @helper/react @ai-sdk/react
Setup
Provider Setup
Wrap your application (or just your support portal) with the HelperClientProvider
to provide the Helper client to all child components:
Provider Props
Parameter | Type | Required | Description |
---|---|---|---|
host | string | ✅ | The base URL of your Helper instance |
session | SessionParams | ✅ | Session configuration (same as Client SDK) |
children | ReactNode | ✅ | Your application components |
queryClient | QueryClient | ❌ | Custom React Query client (optional) |
The provider automatically creates and manages a React Query client if you don't provide one. All hooks use this shared client for caching and synchronization.
Conversation Hooks
useConversations()
Retrieves all conversations for the current session with automatic caching and background updates.
Parameters:
Returns: A React Query object with conversation data.
Example:
useConversation(slug, options?, queryOptions?)
Retrieves a specific conversation with real-time updates and automatic read marking.
Parameters:
slug
(string): The conversation identifieroptions
(object, optional):markRead
(boolean, default:true
): Whether to mark as read when fetchedenableRealtime
(boolean, default:true
): Enable real-time updates
queryOptions
: React Query options
Returns: A React Query object with conversation details.
Example:
useUnreadConversationsCount()
Retrieves the count of unread conversations with automatic updates.
Parameters:
Returns: A React Query object with unread count.
Example:
useCreateConversation()
Mutation hook for creating new conversations.
Parameters:
Returns: A React Query mutation object.
Example:
useUpdateConversation()
Mutation hook for updating existing conversations.
Parameters:
Returns: A React Query mutation object.
Example:
Chat Hook
useChat(options)
Provides a complete chat interface with real-time messaging, typing indicators, and tool integration.
Parameters:
Returns:
Example:
Session Hook
useCreateSession()
Mutation hook for creating new sessions (rarely needed as the provider handles this automatically).
Parameters:
Returns: A React Query mutation object.
Example:
Real-time Features
The React hooks automatically handle real-time updates when enableRealtime
is true (default):
- Conversation updates: Subject changes, new messages from agents
- Typing indicators: Shows when agents are typing
- Message synchronization: Automatically syncs new messages across all components
Real-time features use WebSocket connections managed by the underlying Helper Client SDK. The connections are automatically established and cleaned up when components mount and unmount.
Error Handling
All hooks return standard React Query error states:
TypeScript Support
All hooks are fully typed with TypeScript. Import types as needed:
Best Practices
- Provider Placement: Place
HelperClientProvider
as high as possible in your component tree - Real-time: Enable real-time features for better user experience
- Error Boundaries: Wrap components in error boundaries to handle API failures gracefully
- Loading States: Always handle loading and error states in your UI
- Query Invalidation: The hooks automatically invalidate related queries when data changes