React
React hooks exported by the Customer Agent SDK.
React hooks are exported from @customer-agent/sdk/react.
Exports
| Hook | Signature | Returns | Effect |
|---|---|---|---|
useCustomerAgent | () => CustomerAgentHookController | Controller and state fields | Reads SDK state and exposes SDK methods. |
useCustomerAgentState | () => CustomerAgentState | null | Current state snapshot | Subscribes to SDK ready and visibility changes. |
useCustomerAgentEvent | (eventName, handler) => void | void | Subscribes to an SDK event for the component lifecycle. |
useCustomerAgent Return
| Field | Type | Meaning |
|---|---|---|
CustomerAgent | CustomerAgentGlobal | Raw SDK command function. |
boot | CustomerAgentGlobal["boot"] | SDK boot. |
chooseInvitation | CustomerAgentGlobal["chooseInvitation"] | SDK chooseInvitation. |
ensureInvitation | CustomerAgentGlobal["ensureInvitation"] | SDK ensureInvitation. |
getInterviewSession | CustomerAgentGlobal["getInterviewSession"] | SDK getInterviewSession. |
getInterviewState | CustomerAgentGlobal["getInterviewState"] | SDK getInterviewState. |
getSession | CustomerAgentGlobal["getSession"] | SDK getSession. |
getState | CustomerAgentGlobal["getState"] | SDK getState. |
getSupportState | CustomerAgentGlobal["getSupportState"] | SDK getSupportState. |
hide | CustomerAgentGlobal["hide"] | SDK hide. |
identify | CustomerAgentGlobal["identify"] | SDK identify. |
isOpen | boolean | Current open state. |
isReady | boolean | Current ready state. |
launcher | CustomerAgentState["launcher"] | null | Current launcher state. |
launcherAnchor | HTMLElement | null | Current host launcher node. |
launcherAnchorRef | React.RefObject<HTMLElement | null> | Ref for the host launcher. |
loadInterviewReward | CustomerAgentGlobal["loadInterviewReward"] | SDK loadInterviewReward. |
on | CustomerAgentGlobal["on"] | SDK on. |
openEntry | CustomerAgentGlobal["openEntry"] | SDK openEntry. |
sendInterviewMessage | CustomerAgentGlobal["sendInterviewMessage"] | SDK sendInterviewMessage. |
setContext | CustomerAgentGlobal["setContext"] | SDK setContext. |
show | CustomerAgentGlobal["show"] | SDK show. |
shutdown | CustomerAgentGlobal["shutdown"] | SDK shutdown. |
startInvitation | CustomerAgentGlobal["startInvitation"] | SDK startInvitation. |
state | CustomerAgentState | null | Current state snapshot. |
toggle | CustomerAgentGlobal["toggle"] | SDK toggle. |
update | CustomerAgentGlobal["update"] | SDK update. |
Hook Details
useCustomerAgent
Returns SDK methods plus derived state fields. isOpen, isReady, and launcher are convenience
fields from state. Support and interview methods are also flattened on the returned controller.
launcherAnchor and launcherAnchorRef expose the host-side launcher element currently used as the
Messenger anchor. With a custom launcher, this is the resolved launcher.target element. With the SDK
default launcher, this is the SDK-created host launcher container, not the button inside the launcher
iframe. launcherAnchor updates React rendering when the anchor changes; launcherAnchorRef.current
stores the same element for event handlers and effects.
useCustomerAgentState
Returns the latest CustomerAgentState snapshot, or null before a singleton exists. The hook refreshes on SDK ready/open/close events.
useCustomerAgentEvent
Subscribes to an SDK event for the component lifecycle. The handler receives the typed event payload for the selected event name.