diff --git a/lib/index.ts b/lib/index.ts index 0014c57..6f2a977 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -4,14 +4,10 @@ import React, { useState } from 'react' export type useFormExtractor = (from: any) => any -export type useFormAutoOptions = { - getter?: string, - setter?: string, - extractor?: useFormExtractor -} - export type useFormOptions = { extractor?: useFormExtractor, + getter?: string, + setter?: string, } export type useFormValidatorFunction = ((s: any) => boolean | Promise) @@ -75,9 +71,9 @@ export const useForm = ({ - [opts.getter || 'onChange']: update(key, opts.extractor), - [opts.setter || 'value']: form[key] as any, + const auto = (key: keyof T, opts: useFormOptions = {}) => ({ + [opts.getter || options.getter || 'onChange']: update(key, opts.extractor), + [opts.setter || options.setter || 'value']: form[key] as any, }) return { form, update, auto, errors }