T
TanStack2mo ago
deep-jade

19 generics to FieldApi.. better alternatives for me?

I'm passing a field as prop to a reusable form component that is pretty lenghty and reusable in my forms (the component itself is about 400 lines and handles a lot of logic for setting open hour for a week). Attempting for useField also is the same (19 generics), and not happy about receiving a form typed as ReturnType<typeof useForm<PlaceFormValues>> (ie: const field = useField({ form, name: 'openingHours' });). For clarity, this is my current (pre updating to latest version):
interface DayOpeningHoursProps {
field: FieldApi<
PlaceFormValues,
"openingHours",
undefined,
undefined,
PlaceFormValues["openingHours"]
>;
day: keyof PlaceFormValues["openingHours"];
merged?: boolean;
split?: () => void;
}
interface DayOpeningHoursProps {
field: FieldApi<
PlaceFormValues,
"openingHours",
undefined,
undefined,
PlaceFormValues["openingHours"]
>;
day: keyof PlaceFormValues["openingHours"];
merged?: boolean;
split?: () => void;
}
2 Replies
automatic-azure
automatic-azure2mo ago
if it's UI-based, use Field context from Form Composition. If you need reusable field-level logic or handle multiple fields as a group, take a look at Field Groups. Note that according to our Philosophy section, assigning types should not be required most of the time. That's why you should not use the 19 generics directly, as it's also not considered a breaking change to alter them
deep-jade
deep-jadeOP2mo ago
Appreciate it! Giving it a shot

Did you find this page helpful?