fn
useForwardProps
v0.2.1testedForward a component's props to a child without the ones the
parent never passed. Vue casts an absent Boolean prop to false and fills
the rest with undefined, so spreading props (or a defineProps
destructuring rest) onto a child overrides the child's own defaults —
avoidCollisions = true on PopperContent silently became false in every
composite that re-declared and spread it. Only props present on the
component's own vnode are forwarded, matched by camelCase name, so a parent
writing side-offset counts as having passed sideOffset.
Example
ts
const { forceMount = false, ...popperProps } = defineProps<Props>();
const forwarded = useForwardProps(popperProps);
// <PopperContent v-bind="forwarded">Signature
ts
export function useForwardProps<T extends Record<string, unknown>>(props: T): ComputedRef<Partial<T>>{ ... }Type Parameters
Textends Record<string, unknown>Parameters
| Parameter | Type | Description |
|---|---|---|
props | T | The props object, or a defineProps destructuring rest, to forward |
Returns
ComputedRef<Partial<T>>A reactive subset holding only the props the parent actually passed