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 Parameter | Default type | Description |
|---|---|---|
D extends Record<string, Slot> | Record<string, Slot> | The slot definitions record type |
N extends string | Extract<keyof D, string> | The slot name |
Parameters
| Parameter | Type | Description |
|---|---|---|
slot | N | The slot name to retrieve and wrap |
slots | any | The 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: {} });