Applications often want forms created by the same hook to share a small set of behaviors. createFormHook could support this by accepting non-generic default options, creating a reusable preset that is automatically applied whenever the resulting useAppForm hook is used.
For example:
export const { useAppForm } = createFormHook({
// ...
defaultOptions: {
// NOT: defaultValues, validators, onSubmit
// YES: listeners, onSubmitInvalid, errorVisibility (generalized to `any`?)
errorVisibility: ({ fieldState }) => fieldState.meta.isTouched,
},
})
useAppForm({}) // Contains the default errorVisibility
This would let users configure shared behavior once while continuing to provide form-specific values, validators, and submission logic to each call to useAppForm.
Important
The defaults should be limited to options that do not depend on the form's generic types. Options such as defaultValues, validators, and onSubmit would therefore remain form-specific. Possible defaults include listeners, onSubmitInvalid, and errorVisibility, although supporting errorVisibility may require generalizing its types to any.
Applications often want forms created by the same hook to share a small set of behaviors.
createFormHookcould support this by accepting non-generic default options, creating a reusable preset that is automatically applied whenever the resultinguseAppFormhook is used.For example:
This would let users configure shared behavior once while continuing to provide form-specific values, validators, and submission logic to each call to
useAppForm.Important
The defaults should be limited to options that do not depend on the form's generic types. Options such as
defaultValues,validators, andonSubmitwould therefore remain form-specific. Possible defaults includelisteners,onSubmitInvalid, anderrorVisibility, although supportingerrorVisibilitymay require generalizing its types toany.