Skip to content
Discussion options

You must be logged in to vote

I grabbed the hint from here.

[playground]

import React from 'react';
import { Control, useFieldArray, useForm } from "react-hook-form";

type GenericFormData = {
  theFieldICareAbout: { name: string }[];
};

type FirstFormValues = {
  task: string;
} & GenericFormData;

type SecondFormValues = GenericFormData;

type GenericComponentProps<TFormValues> = {
  control: TFormValues extends GenericFormData ? Control<TFormValues> : never;
};

function GenericComponent<TFormValues extends GenericFormData>({
  control,
}: GenericComponentProps<TFormValues>) {
  const { append } = useFieldArray({
    control,
    name: "theFieldICareAbout",
  });

  const onAppendQuestionGroup = () =>
    append({

Replies: 1 comment 5 replies

Comment options

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

@Blakeinstein
Comment options

@mhuggins
Comment options

@Blakeinstein
Comment options

@alyyousuf7
Comment options

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