Typescript type for generic html props passthrough?
Looking to create a generic wrapper component that can take arbitrary HTML props (class, etc) without manually defining each prop. The Component type is too generic in this case. Is there a simple way to union the Component type with the generic HTML types? React has the
React.HTMLProps
option. Is there recommended approach?5 Replies
Example:
The "simple" solution (to get TS to shutup) is a
props:any
, but I'd really prefer to get type safety passed through.
I found the ComponentProps
type in the source, but it wasn't clear how to use it.
ooh, I think I figured it out?
Is that about right?either ComponentProps or JSX.IntrinsicElements
like
Component<JSX.IntrinsicElements>
?JSX.IntrinsicElements['div']
Thanks!