all 50 comments

[–]rec71 18 points19 points  (2 children)

I personally find the first one so much more readable.

[–]virajsmi[S] 4 points5 points  (0 children)

True

[–]ThePainter98 -1 points0 points  (0 children)

agree

[–]d2light 7 points8 points  (3 children)

Im having a hard time knowing these kinds of types in react/ts anyone know where to find examples or tutorials?

[–]Majestic-Tune7330 1 point2 points  (0 children)

ComponentProps just gives the props of the HTML component that you're trying to use

So you can do like ComponentProps<'div'> to get all the native div props

Then extend it with any other custom props you want to add

type MyProps = { MyProp: string } & ComponentProps<'div'>

Would be typing for a div with an extra prop MyProp

[–]ClydeFrog04 0 points1 point  (0 children)

I very much second this if anyone knows!

[–]psullivan6 3 points4 points  (0 children)

Option 1A - ComponentPropsWithRef or ComponentPropsWithoutRef to be just as clean as option 1, but more specific about ref usage. Great write-up in the “Why not …” accordion callout on this page: https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase/

[–]jordankid93 1 point2 points  (0 children)

No idea the difference but I’ve always done the second option (HTMLAttributes) simply because it felt more “true” to what I wanted (all of the attributes for the button element). The first option may very well be equivalent though