Skip to main content

@dialstack/sdk-dev / react/src / useCreateComponent

Function: useCreateComponent()

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

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

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')

beforeAttach?​

(component) => void

Applies props to the element before it is attached. Attaching is what starts its first load, and the prop effects only run after that, so a setting that shapes the first request belongs here or it costs a second one. Read at creation time; it does not re-run.

Returns​

UseCreateComponentResult<T>

Object with containerRef (callback) and properly typed componentInstance

Example​

TypeScript
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.