Skip to main content

@dialstack/sdk / react / useCreateComponent

Function: useCreateComponent()

function useCreateComponent<T>(dialstack, tagName): UseCreateComponentResult<T>;

Defined in: sdk/src/react/useCreateComponent.tsx:38

Hook to create and manage a Web Component instance

Uses a callback ref pattern for synchronous component creation when the container mounts. Creates components using dialstack.create() and handles cleanup when the container unmounts or when dependencies change.

Type Parameters

T

T extends ComponentTagName

Parameters

dialstack

DialStackInstance

The DialStack instance

tagName

T

The component tag name (e.g., 'call-logs', 'voicemails')

Returns

UseCreateComponentResult<T>

Object with containerRef (callback) and properly typed componentInstance

Example

const { containerRef, componentInstance } = useCreateComponent(dialstack, 'voicemails');
// containerRef is a callback ref to attach to the container div
// componentInstance is typed as VoicemailsElement | null
// TypeScript knows about setUserId, setOnVoicemailPlay, etc.