Skip to content

Type error with generic useFieldArray component (UseFormReset values and values are incompatible) #9789

Answered by martin-wahlberg
tparvi asked this question in Q&A
Discussion options

You must be logged in to vote

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 :)
https://codesandbox.io/s/rhf-generic-field-array-forked-fmc340?file=/src/PersonList.tsx

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@tparvi
Comment options

@dd-jonas
Comment options

@martin-wahlberg
Comment options

@danielmarcano
Comment options

@danielmarcano
Comment options

Answer selected by tparvi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants