Type error with generic useFieldArray component (UseFormReset values and values are incompatible) #9789
-
Codesandbox: https://codesandbox.io/s/rhf-generic-field-array-8ub8ee?file=/src/CustomerForm.tsx I am trying to build generic component that uses
My generic component is:
I try to use my generic component like this:
This is the type error from the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
If you type your component like this it should work: type PersonListProps<FormType extends GenericFormData> = {
control: FormType extends GenericFormData ? Control<FormType> : never;
};
export function PersonList<FormType extends GenericFormData>(
props: PersonListProps<FormType>
): React.ReactElement {
} This makes the ts compiler recognize that the only possible value for props is a controller with the required fields. I updated your code sandbox here :) |
Beta Was this translation helpful? Give feedback.
If you type your component like this it should work:
This makes the ts compiler recognize that the only possible value for props is a controller with the required fields.
I updated your code sandbox here :)
https://codesandbox.io/s/rhf-generic-field-array-forked-fmc340?file=/src/PersonList.tsx