liveBook · Manning

Componentprops

As explained in React in Depth

ComponentProps is a React-provided generic type that derives the property type accepted by a specified component or intrinsic element.

ComponentProps is a React generic utility type for deriving the properties accepted by an intrinsic element or custom component. It avoids manually reproducing large prop surfaces, such as the many attributes and event handlers supported by an <img> element. section 5.3.4

Choose the variant and composition pattern according to the boundary you are designing:

  • Prefer ComponentPropsWithoutRef when the component receives ordinary props and should not expose ref as a regular property. section 5.3.4

A typed wrapper around a rating component

type RatingProps = ComponentPropsWithoutRef<typeof Rating>; type PickedRatingProps = Pick<RatingProps, "value" | "max" | "icon">; interface BookReviewProps extends PickedRatingProps { title: string; reviewer: string; body: string; } function BookReview({ title, reviewer, body, ...rest }: BookReviewProps) { return ( <section className="review"> <Rating max={5} {...rest} /> <h3>{title}</h3> <h4>By {reviewer}</h4> <p>{body}</p> </section> ); }

How React in Depth covers it

How deep it goes
Explains generic selection, ref exclusion, Pick, Omit, and prop forwarding through runnable wrapper examples.
Examples
Uses typed image wrappers and a BookReview component that selectively forwards third-party Rating properties.
What it assumes
Assumes React component and TypeScript interface fundamentals while teaching prop reuse rather than manual prop enumeration.
What you can do after
Build it from scratch by deriving, narrowing, and forwarding intrinsic or custom-component props with TypeScript.
How it connects
Connects React props with TypeScript generics, intrinsic elements, custom components, Pick, Omit, and ref typing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.