Skip to content

Function: useSlotRenderer()

ts
function useSlotRenderer<D, N>(slot: N, slots: any): any;

Creates a slot renderer function that safely invokes a slot with proper typing. Returns a function that will render the slot if provided, or return undefined if not.

Type Parameters

Type ParameterDefault typeDescription
D extends Record<string, Slot>Record<string, Slot>The slot definitions record type
N extends stringExtract<keyof D, string>The slot name

Parameters

ParameterTypeDescription
slotNThe slot name to retrieve and wrap
slotsanyThe slots object from the component

Returns

any

A function that accepts slot parameters and returns the slot's render result or undefined

Example

typescript
const renderLabel = useSlotRenderer<BaseSlots, "label">("label", slots);
// Later in render function:
const labelVNode = renderLabel({ label: "My Label", props: {} });