Function: usePassthroughHook()
ts
function usePassthroughHook<Props, Events, E, P>(
event: E,
emit: (...args: any[]) => void,
callOnKey: Extract<keyof Props, `callOn${string}`> | null | undefined,
props: Props,
attrs: Record<string, unknown>,
options: UsePassthroughHookOptions<P>,
): (...args: P) => Promise<void>;Builds an event invoker that respects component-bound handlers and hook arrays before calling a fallback.
This composable makes it easy to implement events that can be handled via:
- Prop/attribute handlers (onEventName in camelCase or kebab-case)
- Optional "callOnEventName" hook arrays defined on component props
- A provided fallback function when nothing else is registered
The returned function mirrors the event's argument signature. You can also debounce or throttle the produced handler, and control its scheduling (microtask, next tick, or immediate) via UsePassthroughHookOptions.
Event name lookup supports both camel and kebab notations for handlers, e.g.:
- update:modelValue → onUpdateModelValue (camel) and onUpdate:modelValue (kebab)
- item:selected → onItemSelected (camel) and onItem:selected (kebab)
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
Props extends Record<string, any> | - | Component props type including potential onX handlers and callOnX arrays |
Events extends { [key: string]: (...args: any[]) => any; } | - | Map of event names to their function signatures |
E extends string | - | Concrete event name (key of Events) |
P extends any[] | Parameters<Events[E]> | Tuple of the event argument types (derived from Events[E]) |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | E | Event name (e.g., 'update:modelValue') |
emit | (...args: any[]) => void | Vue emit function used when a handler is present |
callOnKey | | Extract<keyof Props, `callOn${string}`> | null | undefined | Name of the prop key that may contain hook array(s), like 'callOnSaving' |
props | Props | Component props object (checked for onX handlers and callOn arrays) |
attrs | Record<string, unknown> | Component attrs object (checked for onX handlers passed via attributes) |
options | UsePassthroughHookOptions<P> | Behavior controls for fallback and scheduling |
Returns
A function with signature (...args: P) => Promise<void> | void to invoke the event
ts
(...args: P): Promise<void>;Parameters
| Parameter | Type |
|---|---|
...args | P |
Returns
Promise<void>