use-validation-form
Version:
React hook for form input handling and validation
29 lines (28 loc) • 790 B
TypeScript
import { ChangeEvent, FormEvent } from 'react';
declare type Validator = (value: any) => string | false;
export interface Validators {
[key: string]: Validator;
}
export interface Values {
[key: string]: any;
}
interface Errors {
[key: string]: string;
}
interface Arguments {
defaultValues: Values;
validators?: Validators;
callback?: () => void;
}
interface ReturnObject {
values: Values;
errors: Errors;
isValid: boolean;
isDirty: boolean;
isSubmitting: boolean;
validateAll: () => void;
onChange: (e: ChangeEvent<any>) => void;
onSubmit: (e: FormEvent<HTMLFormElement>) => void;
}
export declare function useValidationForm({ defaultValues, validators, callback, }: Arguments): ReturnObject;
export {};