UNPKG

28 kBTypeScriptView Raw
1import React from 'react';
2import { VALIDATION_MODE } from '../constants';
3import { Subject, Subscription } from '../utils/createSubject';
4import { ErrorOption, FieldError, FieldErrors } from './errors';
5import { EventType } from './events';
6import { FieldArray } from './fieldArray';
7import { Field, FieldName, FieldRefs, FieldValue, FieldValues, InternalFieldName } from './fields';
8import { FieldArrayPath, FieldPath, FieldPathValue, FieldPathValues } from './path';
9import { Resolver } from './resolvers';
10import { DeepMap, DeepPartial, Noop } from './utils';
11import { RegisterOptions } from './validator';
12declare const $NestedValue: unique symbol;
13/**
14 * @deprecated to be removed in the next major version
15 */
16export type NestedValue<TValue extends object = object> = {
17 [$NestedValue]: never;
18} & TValue;
19/**
20 * @deprecated to be removed in the next major version
21 */
22export type UnpackNestedValue<T> = T extends NestedValue<infer U> ? U : T extends Date | FileList | File | Blob ? T : T extends object ? {
23 [K in keyof T]: UnpackNestedValue<T[K]>;
24} : T;
25export type DefaultValues<TFieldValues> = TFieldValues extends AsyncDefaultValues<TFieldValues> ? DeepPartial<Awaited<TFieldValues>> : DeepPartial<TFieldValues>;
26export type InternalNameSet = Set<InternalFieldName>;
27export type ValidationMode = typeof VALIDATION_MODE;
28export type Mode = keyof ValidationMode;
29export type ValidationModeFlags = {
30 isOnSubmit: boolean;
31 isOnBlur: boolean;
32 isOnChange: boolean;
33 isOnAll: boolean;
34 isOnTouch: boolean;
35};
36export type CriteriaMode = 'firstError' | 'all';
37export type SubmitHandler<TFieldValues extends FieldValues> = (data: TFieldValues, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>;
38export type FormSubmitHandler<TFieldValues extends FieldValues> = (payload: {
39 data: TFieldValues;
40 event?: React.BaseSyntheticEvent;
41 formData: FormData;
42 formDataJson: string;
43 method?: 'post' | 'put' | 'delete';
44}) => unknown | Promise<unknown>;
45export type SubmitErrorHandler<TFieldValues extends FieldValues> = (errors: FieldErrors<TFieldValues>, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>;
46export type SetValueConfig = Partial<{
47 shouldValidate: boolean;
48 shouldDirty: boolean;
49 shouldTouch: boolean;
50}>;
51export type TriggerConfig = Partial<{
52 shouldFocus: boolean;
53}>;
54export type ChangeHandler = (event: {
55 target: any;
56 type?: any;
57}) => Promise<void | boolean>;
58export type DelayCallback = (wait: number) => void;
59type AsyncDefaultValues<TFieldValues> = (payload?: unknown) => Promise<TFieldValues>;
60export type UseFormProps<TFieldValues extends FieldValues = FieldValues, TContext = any> = Partial<{
61 mode: Mode;
62 disabled: boolean;
63 reValidateMode: Exclude<Mode, 'onTouched' | 'all'>;
64 defaultValues: DefaultValues<TFieldValues> | AsyncDefaultValues<TFieldValues>;
65 values: TFieldValues;
66 errors: FieldErrors<TFieldValues>;
67 resetOptions: Parameters<UseFormReset<TFieldValues>>[1];
68 resolver: Resolver<TFieldValues, TContext>;
69 context: TContext;
70 shouldFocusError: boolean;
71 shouldUnregister: boolean;
72 shouldUseNativeValidation: boolean;
73 progressive: boolean;
74 criteriaMode: CriteriaMode;
75 delayError: number;
76}>;
77export type FieldNamesMarkedBoolean<TFieldValues extends FieldValues> = DeepMap<DeepPartial<TFieldValues>, boolean>;
78export type FormStateProxy<TFieldValues extends FieldValues = FieldValues> = {
79 isDirty: boolean;
80 isValidating: boolean;
81 dirtyFields: FieldNamesMarkedBoolean<TFieldValues>;
82 touchedFields: FieldNamesMarkedBoolean<TFieldValues>;
83 validatingFields: FieldNamesMarkedBoolean<TFieldValues>;
84 errors: boolean;
85 isValid: boolean;
86};
87export type ReadFormState = {
88 [K in keyof FormStateProxy]: boolean | 'all';
89};
90export type FormState<TFieldValues extends FieldValues> = {
91 isDirty: boolean;
92 isLoading: boolean;
93 isSubmitted: boolean;
94 isSubmitSuccessful: boolean;
95 isSubmitting: boolean;
96 isValidating: boolean;
97 isValid: boolean;
98 disabled: boolean;
99 submitCount: number;
100 defaultValues?: undefined | Readonly<DeepPartial<TFieldValues>>;
101 dirtyFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>;
102 touchedFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>;
103 validatingFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>;
104 errors: FieldErrors<TFieldValues>;
105};
106export type KeepStateOptions = Partial<{
107 keepDirtyValues: boolean;
108 keepErrors: boolean;
109 keepDirty: boolean;
110 keepValues: boolean;
111 keepDefaultValues: boolean;
112 keepIsSubmitted: boolean;
113 keepIsSubmitSuccessful: boolean;
114 keepTouched: boolean;
115 keepIsValidating: boolean;
116 keepIsValid: boolean;
117 keepSubmitCount: boolean;
118}>;
119export type SetFieldValue<TFieldValues extends FieldValues> = FieldValue<TFieldValues>;
120export type RefCallBack = (instance: any) => void;
121export type UseFormRegisterReturn<TFieldName extends InternalFieldName = InternalFieldName> = {
122 onChange: ChangeHandler;
123 onBlur: ChangeHandler;
124 ref: RefCallBack;
125 name: TFieldName;
126 min?: string | number;
127 max?: string | number;
128 maxLength?: number;
129 minLength?: number;
130 pattern?: string;
131 required?: boolean;
132 disabled?: boolean;
133};
134/**
135 * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.
136 *
137 * @remarks
138 * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)
139 *
140 * @param name - the path name to the form field value, name is required and unique
141 * @param options - register options include validation, disabled, unregister, value as and dependent validation
142 *
143 * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.
144 *
145 * @example
146 * ```tsx
147 * // Register HTML native input
148 * <input {...register("input")} />
149 * <select {...register("select")} />
150 *
151 * // Register options
152 * <textarea {...register("textarea", { required: "This is required.", maxLength: 20 })} />
153 * <input type="number" {...register("name2", { valueAsNumber: true })} />
154 * <input {...register("name3", { deps: ["name2"] })} />
155 *
156 * // Register custom field at useEffect
157 * useEffect(() => {
158 * register("name4");
159 * register("name5", { value: '"hiddenValue" });
160 * }, [register])
161 *
162 * // Register without ref
163 * const { onChange, onBlur, name } = register("name6")
164 * <input onChange={onChange} onBlur={onBlur} name={name} />
165 * ```
166 */
167export type UseFormRegister<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: RegisterOptions<TFieldValues, TFieldName>) => UseFormRegisterReturn<TFieldName>;
168export type SetFocusOptions = Partial<{
169 shouldSelect: boolean;
170}>;
171/**
172 * Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.
173 *
174 * @remarks
175 * [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)
176 *
177 * @param name - the path name to the form field value.
178 * @param options - input focus behavior options
179 *
180 * @example
181 * ```tsx
182 * useEffect(() => {
183 * setFocus("name");
184 * }, [setFocus])
185 * // shouldSelect allows to select input's content on focus
186 * <button onClick={() => setFocus("name", { shouldSelect: true })}>Focus</button>
187 * ```
188 */
189export type UseFormSetFocus<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: SetFocusOptions) => void;
190export type UseFormGetValues<TFieldValues extends FieldValues> = {
191 /**
192 * Get the entire form values when no argument is supplied to this function.
193 *
194 * @remarks
195 * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
196 *
197 * @returns form values
198 *
199 * @example
200 * ```tsx
201 * <button onClick={() => getValues()}>getValues</button>
202 *
203 * <input {...register("name", {
204 * validate: (value, formValues) => formValues.otherField === value;
205 * })} />
206 * ```
207 */
208 (): TFieldValues;
209 /**
210 * Get a single field value.
211 *
212 * @remarks
213 * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
214 *
215 * @param name - the path name to the form field value.
216 *
217 * @returns the single field value
218 *
219 * @example
220 * ```tsx
221 * <button onClick={() => getValues("name")}>getValues</button>
222 *
223 * <input {...register("name", {
224 * validate: () => getValues('otherField') === "test";
225 * })} />
226 * ```
227 */
228 <TFieldName extends FieldPath<TFieldValues>>(name: TFieldName): FieldPathValue<TFieldValues, TFieldName>;
229 /**
230 * Get an array of field values.
231 *
232 * @remarks
233 * [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
234 *
235 * @param names - an array of field names
236 *
237 * @returns An array of field values
238 *
239 * @example
240 * ```tsx
241 * <button onClick={() => getValues(["name", "name1"])}>getValues</button>
242 *
243 * <input {...register("name", {
244 * validate: () => getValues(["fieldA", "fieldB"]).includes("test");
245 * })} />
246 * ```
247 */
248 <TFieldNames extends FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames]): [...FieldPathValues<TFieldValues, TFieldNames>];
249};
250/**
251 * This method will return individual field states. It will be useful when you are trying to retrieve the nested value field state in a typesafe approach.
252 *
253 * @remarks
254 * [API](https://react-hook-form.com/docs/useform/getfieldstate) • [Demo](https://codesandbox.io/s/getfieldstate-jvekk)
255 *
256 * @param name - the path name to the form field value.
257 *
258 * @returns invalid, isDirty, isTouched and error object
259 *
260 * @example
261 * ```tsx
262 * // those formState has to be subscribed
263 * const { formState: { dirtyFields, errors, touchedFields } } = formState();
264 * getFieldState('name')
265 * // Get field state when form state is not subscribed yet
266 * getFieldState('name', formState)
267 *
268 * // It's ok to combine with useFormState
269 * const formState = useFormState();
270 * getFieldState('name')
271 * getFieldState('name', formState)
272 * ```
273 */
274export type UseFormGetFieldState<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues>>(name: TFieldName, formState?: FormState<TFieldValues>) => {
275 invalid: boolean;
276 isDirty: boolean;
277 isTouched: boolean;
278 isValidating: boolean;
279 error?: FieldError;
280};
281export type UseFormWatch<TFieldValues extends FieldValues> = {
282 /**
283 * Watch and subscribe to the entire form update/change based on onChange and re-render at the useForm.
284 *
285 * @remarks
286 * [API](https://react-hook-form.com/docs/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
287 *
288 * @returns return the entire form values
289 *
290 * @example
291 * ```tsx
292 * const formValues = watch();
293 * ```
294 */
295 (): TFieldValues;
296 /**
297 * Watch and subscribe to an array of fields used outside of render.
298 *
299 * @remarks
300 * [API](https://react-hook-form.com/docs/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
301 *
302 * @param names - an array of field names
303 * @param defaultValue - defaultValues for the entire form
304 *
305 * @returns return an array of field values
306 *
307 * @example
308 * ```tsx
309 * const [name, name1] = watch(["name", "name1"]);
310 * ```
311 */
312 <TFieldNames extends readonly FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames], defaultValue?: DeepPartial<TFieldValues>): FieldPathValues<TFieldValues, TFieldNames>;
313 /**
314 * Watch and subscribe to a single field used outside of render.
315 *
316 * @remarks
317 * [API](https://react-hook-form.com/docs/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
318 *
319 * @param name - the path name to the form field value.
320 * @param defaultValue - defaultValues for the entire form
321 *
322 * @returns return the single field value
323 *
324 * @example
325 * ```tsx
326 * const name = watch("name");
327 * ```
328 */
329 <TFieldName extends FieldPath<TFieldValues>>(name: TFieldName, defaultValue?: FieldPathValue<TFieldValues, TFieldName>): FieldPathValue<TFieldValues, TFieldName>;
330 /**
331 * Subscribe to field update/change without trigger re-render
332 *
333 * @remarks
334 * [API](https://react-hook-form.com/docs/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
335 *
336 * @param callback - call back function to subscribe all fields change and return unsubscribe function
337 * @param defaultValues - defaultValues for the entire form
338 *
339 * @returns unsubscribe function
340 *
341 * @example
342 * ```tsx
343 * useEffect(() => {
344 * const { unsubscribe } = watch((value) => {
345 * console.log(value);
346 * });
347 * return () => unsubscribe();
348 * }, [watch])
349 * ```
350 */
351 (callback: WatchObserver<TFieldValues>, defaultValues?: DeepPartial<TFieldValues>): Subscription;
352};
353/**
354 * Trigger field or form validation
355 *
356 * @remarks
357 * [API](https://react-hook-form.com/docs/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)
358 *
359 * @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an array of fields, and a single field name will only trigger that field's validation.
360 * @param options - should focus on the error field
361 *
362 * @returns validation result
363 *
364 * @example
365 * ```tsx
366 * useEffect(() => {
367 * trigger();
368 * }, [trigger])
369 *
370 * <button onClick={async () => {
371 * const result = await trigger(); // result will be a boolean value
372 * }}>
373 * trigger
374 * </button>
375 * ```
376 */
377export type UseFormTrigger<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: TriggerConfig) => Promise<boolean>;
378/**
379 * Clear the entire form errors.
380 *
381 * @remarks
382 * [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)
383 *
384 * @param name - the path name to the form field value.
385 *
386 * @example
387 * Clear all errors
388 * ```tsx
389 * clearErrors(); // clear the entire form error
390 * clearErrors(["name", "name1"]) // clear an array of fields' error
391 * clearErrors("name2"); // clear a single field error
392 * ```
393 */
394export type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[] | `root.${string}` | 'root') => void;
395/**
396 * Set a single field value, or a group of fields value.
397 *
398 * @remarks
399 * [API](https://react-hook-form.com/docs/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)
400 *
401 * @param name - the path name to the form field value.
402 * @param value - field value
403 * @param options - should validate or update form state
404 *
405 * @example
406 * ```tsx
407 * // Update a single field
408 * setValue('name', 'value', {
409 * shouldValidate: true, // trigger validation
410 * shouldTouch: true, // update touched fields form state
411 * shouldDirty: true, // update dirty and dirty fields form state
412 * });
413 *
414 * // Update a group fields
415 * setValue('root', {
416 * a: 'test', // setValue('root.a', 'data')
417 * b: 'test1', // setValue('root.b', 'data')
418 * });
419 *
420 * // Update a nested object field
421 * setValue('select', { label: 'test', value: 'Test' });
422 * ```
423 */
424export type UseFormSetValue<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, value: FieldPathValue<TFieldValues, TFieldName>, options?: SetValueConfig) => void;
425/**
426 * Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.
427 *
428 * @remarks
429 * [API](https://react-hook-form.com/docs/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)
430 *
431 * @param name - the path name to the form field value.
432 * @param error - an error object which contains type and optional message
433 * @param options - whether or not to focus on the field
434 *
435 * @example
436 * ```tsx
437 * // when the error is not associated with any fields, `clearError` will need to invoke to clear the error
438 * const onSubmit = () => setError("serverError", { type: "server", message: "Error occurred"})
439 *
440 * <button onClick={() => setError("name", { type: "min" })} />
441 *
442 * // focus on the input after setting the error
443 * <button onClick={() => setError("name", { type: "max" }, { shouldFocus: true })} />
444 * ```
445 */
446export type UseFormSetError<TFieldValues extends FieldValues> = (name: FieldPath<TFieldValues> | `root.${string}` | 'root', error: ErrorOption, options?: {
447 shouldFocus: boolean;
448}) => void;
449/**
450 * Unregister a field reference and remove its value.
451 *
452 * @remarks
453 * [API](https://react-hook-form.com/docs/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)
454 *
455 * @param name - the path name to the form field value.
456 * @param options - keep form state options
457 *
458 * @example
459 * ```tsx
460 * register("name", { required: true })
461 *
462 * <button onClick={() => unregister("name")} />
463 * // there are various keep options to retain formState
464 * <button onClick={() => unregister("name", { keepErrors: true })} />
465 * ```
466 */
467export type UseFormUnregister<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: Omit<KeepStateOptions, 'keepIsSubmitted' | 'keepSubmitCount' | 'keepValues' | 'keepDefaultValues' | 'keepErrors'> & {
468 keepValue?: boolean;
469 keepDefaultValue?: boolean;
470 keepError?: boolean;
471}) => void;
472/**
473 * Validate the entire form. Handle submit and error callback.
474 *
475 * @remarks
476 * [API](https://react-hook-form.com/docs/useform/handlesubmit) • [Demo](https://codesandbox.io/s/react-hook-form-handlesubmit-ts-v7-lcrtu) • [Video](https://www.youtube.com/watch?v=KzcPKB9SOEk)
477 *
478 * @param onValid - callback function invoked after form pass validation
479 * @param onInvalid - callback function invoked when form failed validation
480 *
481 * @returns callback - return callback function
482 *
483 * @example
484 * ```tsx
485 * const onSubmit = (data) => console.log(data);
486 * const onError = (error) => console.log(error);
487 *
488 * <form onSubmit={handleSubmit(onSubmit, onError)} />
489 * ```
490 */
491export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = (onValid: TTransformedValues extends undefined ? SubmitHandler<TFieldValues> : TTransformedValues extends FieldValues ? SubmitHandler<TTransformedValues> : never, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>;
492/**
493 * Reset a field state and reference.
494 *
495 * @remarks
496 * [API](https://react-hook-form.com/docs/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)
497 *
498 * @param name - the path name to the form field value.
499 * @param options - keep form state options
500 *
501 * @example
502 * ```tsx
503 * <input {...register("firstName", { required: true })} />
504 * <button type="button" onClick={() => resetField("firstName"))}>Reset</button>
505 * ```
506 */
507export type UseFormResetField<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: Partial<{
508 keepDirty: boolean;
509 keepTouched: boolean;
510 keepError: boolean;
511 defaultValue: FieldPathValue<TFieldValues, TFieldName>;
512}>) => void;
513type ResetAction<TFieldValues> = (formValues: TFieldValues) => TFieldValues;
514/**
515 * Reset at the entire form state.
516 *
517 * @remarks
518 * [API](https://react-hook-form.com/docs/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)
519 *
520 * @param values - the entire form values to be reset
521 * @param keepStateOptions - keep form state options
522 *
523 * @example
524 * ```tsx
525 * useEffect(() => {
526 * // reset the entire form after component mount or form defaultValues is ready
527 * reset({
528 * fieldA: "test"
529 * fieldB: "test"
530 * });
531 * }, [reset])
532 *
533 * // reset by combine with existing form values
534 * reset({
535 * ...getValues(),
536 * fieldB: "test"
537 *});
538 *
539 * // reset and keep form state
540 * reset({
541 * ...getValues(),
542 *}, {
543 * keepErrors: true,
544 * keepDirty: true
545 *});
546 * ```
547 */
548export type UseFormReset<TFieldValues extends FieldValues> = (values?: DefaultValues<TFieldValues> | TFieldValues | ResetAction<TFieldValues>, keepStateOptions?: KeepStateOptions) => void;
549export type WatchInternal<TFieldValues> = (fieldNames?: InternalFieldName | InternalFieldName[], defaultValue?: DeepPartial<TFieldValues>, isMounted?: boolean, isGlobal?: boolean) => FieldPathValue<FieldValues, InternalFieldName> | FieldPathValues<FieldValues, InternalFieldName[]>;
550export type GetIsDirty = <TName extends InternalFieldName, TData>(name?: TName, data?: TData) => boolean;
551export type FormStateSubjectRef<TFieldValues extends FieldValues> = Subject<Partial<FormState<TFieldValues>> & {
552 name?: InternalFieldName;
553}>;
554export type Subjects<TFieldValues extends FieldValues = FieldValues> = {
555 values: Subject<{
556 name?: InternalFieldName;
557 type?: EventType;
558 values: FieldValues;
559 }>;
560 array: Subject<{
561 name?: InternalFieldName;
562 values?: FieldValues;
563 }>;
564 state: FormStateSubjectRef<TFieldValues>;
565};
566export type Names = {
567 mount: InternalNameSet;
568 unMount: InternalNameSet;
569 array: InternalNameSet;
570 watch: InternalNameSet;
571 focus?: InternalFieldName;
572 watchAll?: boolean;
573};
574export type BatchFieldArrayUpdate = <T extends Function, TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>(name: InternalFieldName, updatedFieldArrayValues?: Partial<FieldArray<TFieldValues, TFieldArrayName>>[], method?: T, args?: Partial<{
575 argA: unknown;
576 argB: unknown;
577}>, shouldSetValue?: boolean, shouldUpdateFieldsAndErrors?: boolean) => void;
578export type Control<TFieldValues extends FieldValues = FieldValues, TContext = any> = {
579 _subjects: Subjects<TFieldValues>;
580 _removeUnmounted: Noop;
581 _names: Names;
582 _state: {
583 mount: boolean;
584 action: boolean;
585 watch: boolean;
586 };
587 _reset: UseFormReset<TFieldValues>;
588 _options: UseFormProps<TFieldValues, TContext>;
589 _getDirty: GetIsDirty;
590 _resetDefaultValues: Noop;
591 _formState: FormState<TFieldValues>;
592 _updateValid: (shouldUpdateValid?: boolean) => void;
593 _updateFormState: (formState: Partial<FormState<TFieldValues>>) => void;
594 _fields: FieldRefs;
595 _formValues: FieldValues;
596 _proxyFormState: ReadFormState;
597 _defaultValues: Partial<DefaultValues<TFieldValues>>;
598 _getWatch: WatchInternal<TFieldValues>;
599 _updateFieldArray: BatchFieldArrayUpdate;
600 _getFieldArray: <TFieldArrayValues>(name: InternalFieldName) => Partial<TFieldArrayValues>[];
601 _setErrors: (errors: FieldErrors<TFieldValues>) => void;
602 _updateDisabledField: (props: {
603 disabled?: boolean;
604 name: FieldName<any>;
605 value?: unknown;
606 } & ({
607 field?: Field;
608 fields?: undefined;
609 } | {
610 field?: undefined;
611 fields?: FieldRefs;
612 })) => void;
613 _executeSchema: (names: InternalFieldName[]) => Promise<{
614 errors: FieldErrors;
615 }>;
616 register: UseFormRegister<TFieldValues>;
617 handleSubmit: UseFormHandleSubmit<TFieldValues>;
618 _disableForm: (disabled?: boolean) => void;
619 unregister: UseFormUnregister<TFieldValues>;
620 getFieldState: UseFormGetFieldState<TFieldValues>;
621 setError: UseFormSetError<TFieldValues>;
622};
623export type WatchObserver<TFieldValues extends FieldValues> = (value: DeepPartial<TFieldValues>, info: {
624 name?: FieldPath<TFieldValues>;
625 type?: EventType;
626 values?: unknown;
627}) => void;
628export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined> = {
629 watch: UseFormWatch<TFieldValues>;
630 getValues: UseFormGetValues<TFieldValues>;
631 getFieldState: UseFormGetFieldState<TFieldValues>;
632 setError: UseFormSetError<TFieldValues>;
633 clearErrors: UseFormClearErrors<TFieldValues>;
634 setValue: UseFormSetValue<TFieldValues>;
635 trigger: UseFormTrigger<TFieldValues>;
636 formState: FormState<TFieldValues>;
637 resetField: UseFormResetField<TFieldValues>;
638 reset: UseFormReset<TFieldValues>;
639 handleSubmit: UseFormHandleSubmit<TFieldValues, TTransformedValues>;
640 unregister: UseFormUnregister<TFieldValues>;
641 control: Control<TFieldValues, TContext>;
642 register: UseFormRegister<TFieldValues>;
643 setFocus: UseFormSetFocus<TFieldValues>;
644};
645export type UseFormStateProps<TFieldValues extends FieldValues> = Partial<{
646 control?: Control<TFieldValues>;
647 disabled?: boolean;
648 name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[];
649 exact?: boolean;
650}>;
651export type UseFormStateReturn<TFieldValues extends FieldValues> = FormState<TFieldValues>;
652export type UseWatchProps<TFieldValues extends FieldValues = FieldValues> = {
653 defaultValue?: unknown;
654 disabled?: boolean;
655 name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[];
656 control?: Control<TFieldValues>;
657 exact?: boolean;
658};
659export type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined> = {
660 children: React.ReactNode | React.ReactNode[];
661} & UseFormReturn<TFieldValues, TContext, TTransformedValues>;
662export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onError' | 'onSubmit'> & Partial<{
663 control: Control<TFieldValues>;
664 headers: Record<string, string>;
665 validateStatus: (status: number) => boolean;
666 onError: ({ response, error, }: {
667 response: Response;
668 error?: undefined;
669 } | {
670 response?: undefined;
671 error: unknown;
672 }) => void;
673 onSuccess: ({ response }: {
674 response: Response;
675 }) => void;
676 onSubmit: TTransformedValues extends FieldValues ? FormSubmitHandler<TTransformedValues> : FormSubmitHandler<TFieldValues>;
677 method: 'post' | 'put' | 'delete';
678 children: React.ReactNode | React.ReactNode[];
679 render: (props: {
680 submit: (e?: React.FormEvent) => void;
681 }) => React.ReactNode | React.ReactNode[];
682 encType: 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain' | 'application/json';
683}>;
684export {};
685//# sourceMappingURL=form.d.ts.map
\No newline at end of file