My goal is to make a component which instances a provider as well as an HTMLDivElement beneath that provider, where it will take all the props of an HTMLDivElement and a ref to forward to that element
for the sake of simplicity, let's say it's as follows:
interface FormFieldProps<TName extends string> extends ComponentPropsWithRef<'div'> {
name: TName;
}
function FormField<TName extends string>(
{ name, ...props }: FormFieldProps<TName>,
ref: ForwardedRef<HTMLDivElement>
) {
// ... this really doesn't matter
}
However, I am having a bit of trouble forwarding the ref, while keeping it generic. I tried the following:
interface FormFieldProps<TName extends string> extends ComponentPropsWithRef<'div'> {
name: TName;
}
type ForwardFormFieldRef= <TName extends string, T = HTMLDivElement>(render: ForwardRefRenderFunction<T, FormFieldProps<TName>>) => ForwardRefExoticComponent<PropsWithoutRef<FormFieldProps<TName>> & RefAttributes<T>>;
const forwardFormFieldRef = forwardRef as ForwardFormFieldRef;
const FormField = forwardFormFieldRef(FormField);
This doesn't work, though. Anyone got any ideas? This is kinda a PITA ngl