diff --git a/lib/index.ts b/lib/index.ts index 0b31487..4329373 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -29,7 +29,11 @@ function isFormValidatorObject(validator: useFormValidatorMethod | useFormValida const defaultErrorMessage = (key: any) => `Error in ${key}` -export const useForm = (init: T, validators: Partial = {}, options: useFormOptions = {}) => { +export const useForm = ( + init: T, + validators: Partial = {}, + options: useFormOptions = {} +) => { const [form, setForm] = useState(init) const [errors, setErrors] = useState>({}) @@ -39,7 +43,7 @@ export const useForm = acc || cur !== undefined, false)) }, [errors]) - const _set = (key: keyof T, value: any) => { + const _set = (key: A, value: T[A]) => { setForm({ ...form, [key]: value, @@ -82,7 +86,7 @@ export const useForm = (value: any) => { + const update = (key: A, extractor = options.extractor) => (value: T[A]) => { const extracted = extractor ? extractor(value) : HTMLInputExtractor(value) _set(key, extracted) _validate(key, extracted) @@ -93,5 +97,5 @@ export const useForm =