forwardGenericRef
Size
0.10 kb
Same as React.forwardRef
, but works with generic functions.
import { forwardGenericRef } from 'crustack/utils'
const defaultTag = 'div' as const
type Props<TComponent extends React.ElementType<any> = typeof defaultTag> = React.ComponentPropsWithoutRef<TComponent> & { as?: TComponent }
const ComponentAs = forwardGenericRef( <TComponent extends React.ElementType<any>>({ as, ...props }: Props<TComponent>) => { const Comp = as || defaultTag return <Comp {...props} /> },)