Radix
Extending a primitive
React.ElementRef<typeof AccordionPrimitive.Item>
: Ensures thatMyAccordionItem
forwards the correctref
type to the underlyingAccordionPrimitive.Item
.React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
: specifies theprops
that can be passed toMyAccordionItem
, excluding theref
prop, as it's handled separately.
import * as React from 'react'
import * as AccordionPrimitive from '@radix-ui/react-accordion'
const MyAccordionItem = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
className={cn('baseClasses...', className)}
{...props}
/>
))
MyAccordionItem.displayName = 'MyAccordionItem'