Validator functions
Validator functions can either by synchronous or asynchronous.
These functions must resolve with native Error
instance if the validation should fail, or with undefined
if the validation should pass.
type ValidationResult = Error | undefined
Synchronous
type Validator<
TForm,
TMeta extends Record<string, unknown> = Record<string, unknown>
> = (form: TForm, meta: TMeta) => ValidationResult
Suitable for quick client side validations like empty fields, or regex statements.
Asynchronous
type AsyncValidator<
TForm,
TMeta extends Record<string, unknown> = Record<string, unknown>
> = (form: TForm, signal: AbortSignal, meta: TMeta) => Promise<ValidationResult>
Suitable for any kind of validation that must be resolved with a Promise.
Function is called with the latest form values and the fresh instance of AbortSignal that can be used to cancel in flight requests.