So I have a form with one select (user_id), one input (year) and form to upload PDF document
I made a custom validation using watch from React Hook Form. The problem is that there is a TS error
Property ‘unsubscribe’ does not exist on type ‘readonly (string | File | { file: File; title: string; } | { file: File; title: string; }[])[]’.
What could be the reason ?
type TaxDocumentsFormType = {
user_id: string;
year: string;
tax_doc: { file: File; title: string }[];
};
const {
handleSubmit,
setValue,
control,
register,
getValues,
watch,
formState: { isSubmitting, errors },
} = useForm<TaxDocumentsFormType>({
defaultValues: {
year: '',
tax_doc: [],
},
mode: 'onChange',
});
useEffect(() => {
const subscription = watch(
({ year, user_id, tax_doc }: TaxDocumentsFormType) => {
const yearIsValid = YEAR_REGEX.test(year);
const investorIsValid = user_id !== '';
const documentIsValid = tax_doc && tax_doc.length > 0;
setFormIsValid(
yearIsValid && investorIsValid && documentIsValid
);
}
);
return () => {
subscription.unsubscribe();
};
}, [watch]);