Customer Agent

React

React hooks exported by the Customer Agent SDK.

React hooks are exported from @customer-agent/sdk/react.

Exports

HookSignatureReturnsEffect
useCustomerAgent() => CustomerAgentHookControllerController and state fieldsReads SDK state and exposes SDK methods.
useCustomerAgentState() => CustomerAgentState | nullCurrent state snapshotSubscribes to SDK ready and visibility changes.
useCustomerAgentEvent(eventName, handler) => voidvoidSubscribes to an SDK event for the component lifecycle.

useCustomerAgent Return

FieldTypeMeaning
CustomerAgentCustomerAgentGlobalRaw SDK command function.
bootCustomerAgentGlobal["boot"]SDK boot.
chooseInvitationCustomerAgentGlobal["chooseInvitation"]SDK chooseInvitation.
ensureInvitationCustomerAgentGlobal["ensureInvitation"]SDK ensureInvitation.
getInterviewSessionCustomerAgentGlobal["getInterviewSession"]SDK getInterviewSession.
getInterviewStateCustomerAgentGlobal["getInterviewState"]SDK getInterviewState.
getSessionCustomerAgentGlobal["getSession"]SDK getSession.
getStateCustomerAgentGlobal["getState"]SDK getState.
getSupportStateCustomerAgentGlobal["getSupportState"]SDK getSupportState.
hideCustomerAgentGlobal["hide"]SDK hide.
identifyCustomerAgentGlobal["identify"]SDK identify.
isOpenbooleanCurrent open state.
isReadybooleanCurrent ready state.
launcherCustomerAgentState["launcher"] | nullCurrent launcher state.
launcherAnchorHTMLElement | nullCurrent host launcher node.
launcherAnchorRefReact.RefObject<HTMLElement | null>Ref for the host launcher.
loadInterviewRewardCustomerAgentGlobal["loadInterviewReward"]SDK loadInterviewReward.
onCustomerAgentGlobal["on"]SDK on.
openEntryCustomerAgentGlobal["openEntry"]SDK openEntry.
sendInterviewMessageCustomerAgentGlobal["sendInterviewMessage"]SDK sendInterviewMessage.
setContextCustomerAgentGlobal["setContext"]SDK setContext.
showCustomerAgentGlobal["show"]SDK show.
shutdownCustomerAgentGlobal["shutdown"]SDK shutdown.
startInvitationCustomerAgentGlobal["startInvitation"]SDK startInvitation.
stateCustomerAgentState | nullCurrent state snapshot.
toggleCustomerAgentGlobal["toggle"]SDK toggle.
updateCustomerAgentGlobal["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.

On this page