import { ForwardedRef, ReactElement, RefAttributes, forwardRef, PropsWithoutRef } from 'react'; /** * This works like React.forwardRef but for components with generic props. * @warning Don't use this if your component type isn't generic => `const Component = () => {...}` and displayName is not supported yet */ export function typedForwardRef( render: (props: PropsWithoutRef

, ref: ForwardedRef) => ReactElement | null, ): (props: P & RefAttributes) => ReactElement | null { // forwardRef expects (props: PropsWithoutRef

, ref: ForwardedRef) return forwardRef(render) as unknown as (props: P & RefAttributes) => ReactElement | null; }