UNPKG

@matthew.ngo/reform

Version:

A flexible and powerful React form management library with advanced validation, state observation, and multi-group support

30 lines (29 loc) 935 B
import { UseFormWatch } from 'react-hook-form'; import { FieldWatcherReturn } from './types'; import { FormGroup } from '../../core/form/form-groups'; /** * Hook for watching specific field changes across form groups * * @template T - Form data type * @param watch - React Hook Form watch function * @returns Object with field watching utilities * * @example * const form = useReform(config); * const { watch } = form.formMethods; * const fieldWatcher = useFieldWatcher<FormData>(watch); * * // Watch email field changes * useEffect(() => { * const unsubscribe = fieldWatcher.watchField({ * field: 'email', * callback: (value) => validateEmailAsync(value), * debounce: 500 * }); * * return unsubscribe; * }, []); */ export declare const useFieldWatcher: <T extends Record<string, any>>(watch: UseFormWatch<{ groups: FormGroup<T>[]; }>) => FieldWatcherReturn<T>;