ComponentProps
The props type of a component, or of an intrinsic element tag name: use it to wrap or forward the props of an element or another component.
The props type of a component, or of an intrinsic element tag name: use it to wrap or forward the props of an element or another component.
Import#
ts
import type { ComponentProps } from "@shadow-js/web";
Signature#
ts
type ComponentProps<T extends ValidComponent> = T extends keyof JSX.IntrinsicElements
? JSX.IntrinsicElements[T]
: T extends (props: infer P) => unknown
? P
: never
Examples#
ts
import type { ComponentProps, JSX } from "@shadow-js/web";
function Card(props: { title: string }): JSX.Element {
return <h2>{props.title}</h2>;
}
type InputProps = ComponentProps<"input">; // the attributes of <input>
type CardProps = ComponentProps<typeof Card>; // { title: string }