Answer the question
In order to leave comments, you need to log in
How to create a type from an existing type that will only have some fields of the existing type?
Greetings.
There is the following code:
type FormProps<T extends FieldValues> = {
defaultValues?: DefaultValues<T>;
onSubmit: (data: UnpackNestedValue<T>) => void;
children: ({ register, formState }: UseFormReturn<T>) => ReactNode;
};
export const Form = <T,>({ defaultValues, onSubmit, children }: FormProps<T>) => {
const { handleSubmit, reset, setValue, control, register } = useForm({ defaultValues });
return <form onSubmit={handleSubmit(onSubmit)}>{children({ register, formState })}</form>;
};
...
children: ({ register, formState }: { register: UseFormRegister<T>, formState: FormState<T> }) => ReactNode;
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question