RealTimeX
Sign inStart for free
RealTimeXWeb Package
IntroductionPrerequisitesInstallationProject setupQuick start
Package structureConfigurationComponentsHooksAPI integrationSocket events
OverviewReplace entire UIReplace componentsStyle with classNamesThemes & localePhone & video callingIn-call control barFeatures
Unread badgeRich-text messagesPins, stars & datesMessage threadsMentionsCanvas & draftsNotificationsAdmin permissionsServer refusalsSession & token refresh
Host app integrationTroubleshootingFAQVersion historyBest practicesSupport & contact
Web packagePackage reference

Hooks

All hooks are available from the package root and must be used inside a Chat / ChatMain provider tree - except useTotalUnreadCount, which works anywhere as long as a chat instance is mounted.

All hooks at a glance

Hook / exportPurpose
useChatController()State + handlers inside a custom ChatLayout (Case 1)
useChatStore()Zustand store - messages, conversations, socket actions
useTotalUnreadCount()Workspace-wide unread badge - Unread badge
fetchUnreadCount()One-shot REST fetch of the unread summary
useChatCustomization()Current components / classNames inside custom children
useChatFeatures()Phone/video flags and callbacks
useChatTheme()themeColor, isDark, CSS variables
useChatLocale()Format dates/times with the current locale
useChatAlerts()Error/info alert state
useChatContext()Low-level chat provider context
useEffectiveSettingsOptional()Workspace admin settings + gate helpers - Admin permissions
useAdminFeatureGate(key){ visible, enabled, disabledReason } for one feature
usePushNotifications()Web push state + enable/disable on this device - Notifications
useNotificationPreferences()The user's notification preferences (load / update)
useCanvasStore()Canvas open/list state - Canvas
useCallStore()Calling state machine - Phone & video calling
tsx
1import { useChatStore } from "@realtimexsco/live-chat";2 3const conversations = useChatStore((s) => s.conversations);4const emitDmSend = useChatStore((s) => s.emitDmSend);

useChatStore

Zustand store selector hook. Access any slice of chat state or any store action.

ParameterReturn valueNotes
selector: (state) => TT - the selected slice of stateRe-renders only when the selected value changes
tsx
1import { useChatStore } from "@realtimexsco/live-chat";2 3const conversations = useChatStore((s) => s.conversations);4const emitDmSend = useChatStore((s) => s.emitDmSend);5const allUsers = useChatStore((s) => s.allUsers);6const manageGroupMembers = useChatStore((s) => s.manageGroupMembers);7const loggedUserDetails = useChatStore((s) => s.loggedUserDetails);

useChatController

Provides the state and handlers needed to build a fully custom ChatLayout. See Replace entire UI.

Return valueDescription
activeChannelThe currently selected conversation/channel object
conversationIdId of the active conversation
conversationMessagesMessages loaded for the active conversation
handleChannelSelectSelects a channel and loads its messages
handleSendMessageSends a message in the active conversation
setActiveChannelManually sets the active channel
state / updateStateInternal UI state and its setter
tsx
1const {2  activeChannel,3  conversationId,4  conversationMessages,5  handleChannelSelect,6  handleSendMessage,7  setActiveChannel,8  state,9  updateState,10} = useChatController();

useChatContext

Low-level access to the raw chat provider context - mainly useful for advanced integrations that need values not exposed by useChatController. Prefer controller or store hooks for normal UI work.

tsx
1import { useChatContext } from "@realtimexsco/live-chat";2 3const ctx = useChatContext();4// Inspect provider values for diagnostics - avoid coupling UI deeply to this API

useChatCustomization / useChatCustomizationOptional

Reads the currently merged components and classNames configuration inside custom child components. Use this when a slot needs to know which overrides are active. The Optional variant returns undefined instead of throwing when used outside a provider.

tsx
1import {2  useChatCustomization,3  useChatCustomizationOptional,4} from "@realtimexsco/live-chat";5 6const { components, classNames } = useChatCustomization();7const maybe = useChatCustomizationOptional(); // undefined outside ChatMain

useChatFeatures / useChatFeaturesOptional

Reads the current phone/video call flags and their callbacks (showPhoneCall, showVideoCall, onPhoneCall, onVideoCall). Useful inside a custom HeaderCallActions slot.

tsx
1import { useChatFeatures } from "@realtimexsco/live-chat";2 3const { showPhoneCall, showVideoCall, onPhoneCall, onVideoCall } =4  useChatFeatures();

useChatTheme

Returns themeColor, isDark, and the resolved CSS variables driving the brand accent. Use this when a custom component must match the active chat theme without hard-coding colors.

tsx
1import { useChatTheme } from "@realtimexsco/live-chat";2 3const { themeColor, isDark } = useChatTheme();

useChatLocale

Formats dates and times using the active locale, timeZone, and hour12 setting passed to ChatMain. Prefer this over ad-hoc Intl calls so timestamps stay consistent across slots.

tsx
1import { useChatLocale } from "@realtimexsco/live-chat";2 3const { formatDateTime, locale, timeZone, hour12 } = useChatLocale();4const label = formatDateTime(message.createdAt);

useChatAlerts

Reads and controls the current error/info alert bar state shown above the chat shell. Use it to surface API failures or clear banners after recovery.

tsx
1import { useChatAlerts } from "@realtimexsco/live-chat";2 3const { alert, showAlert, clearAlert } = useChatAlerts();4showAlert({ type: "error", message: "Could not load messages" });
PreviousComponentsNextAPI integration

On this page

All hooks at a glanceuseChatStoreuseChatControlleruseChatContextuseChatCustomization / useChatCustomizationOptionaluseChatFeatures / useChatFeaturesOptionaluseChatThemeuseChatLocaleuseChatAlerts
Back to top