-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
27 lines (23 loc) · 899 Bytes
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
declare module 'use-form-react' {
import React from 'react';
export type ValidationFunc<Fields> = (fields: Fields) => string | undefined;
export interface UseFormConfig<Fields extends Record<string, any>> {
initialValues?: Partial<Fields>;
validation?: Partial<Record<keyof Fields, ValidationFunc<Fields>>>;
debug?: boolean;
callback?: (inputs: Fields)=> void;
}
export interface UseFormState<Fields> {
onSubmit: (event: React.SyntheticEvent<HTMLFormElement>) => void,
onChange: (event: React.SyntheticEvent<HTMLInputElement>) => void,
inputs: Fields,
submitting: boolean,
dirty: boolean,
reset: () => void,
setInputs: (fields: Fields) => void,
errors: Record<keyof Fields, string>,
valid: boolean,
}
const useForm: <Fields = any>(name: string, config: UseFormConfig<Fields>) => UseFormState<Fields>;
export default useForm;
}