react-hook-form 8.0.0-beta.2 → 8.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -20
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/controller.d.ts +8 -37
- package/dist/controller.d.ts.map +1 -1
- package/dist/errorMessage.d.ts +27 -0
- package/dist/errorMessage.d.ts.map +1 -0
- package/dist/fieldArray.d.ts +37 -0
- package/dist/fieldArray.d.ts.map +1 -0
- package/dist/form.d.ts +8 -17
- package/dist/form.d.ts.map +1 -1
- package/dist/formState.d.ts +12 -0
- package/dist/formState.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.mjs +2952 -2347
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/collectDirtyFieldNames.d.ts +3 -0
- package/dist/logic/collectDirtyFieldNames.d.ts.map +1 -0
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/logic/generateId.d.ts.map +1 -1
- package/dist/logic/getCheckboxValue.d.ts.map +1 -1
- package/dist/logic/getDirtyFields.d.ts +3 -2
- package/dist/logic/getDirtyFields.d.ts.map +1 -1
- package/dist/logic/getEventValue.d.ts.map +1 -1
- package/dist/logic/{getFieldArrayParentNames.d.ts → getFieldArrayItemNames.d.ts} +1 -1
- package/dist/logic/getFieldArrayItemNames.d.ts.map +1 -0
- package/dist/logic/getFieldValue.d.ts.map +1 -1
- package/dist/logic/getNullAncestorValue.d.ts +5 -0
- package/dist/logic/getNullAncestorValue.d.ts.map +1 -0
- package/dist/logic/getProxyFormState.d.ts +1 -1
- package/dist/logic/getProxyFormState.d.ts.map +1 -1
- package/dist/logic/getResolverOptions.d.ts +1 -0
- package/dist/logic/getResolverOptions.d.ts.map +1 -1
- package/dist/logic/getValueAndMessage.d.ts +1 -4
- package/dist/logic/getValueAndMessage.d.ts.map +1 -1
- package/dist/logic/hasPromiseValidation.d.ts.map +1 -1
- package/dist/logic/hasValidation.d.ts +1 -1
- package/dist/logic/hasValidation.d.ts.map +1 -1
- package/dist/logic/index.d.ts +2 -3
- package/dist/logic/index.d.ts.map +1 -1
- package/dist/logic/isNameInFieldArray.d.ts +4 -0
- package/dist/logic/isNameInFieldArray.d.ts.map +1 -0
- package/dist/logic/isWatched.d.ts.map +1 -1
- package/dist/logic/iterateFieldsByAction.d.ts +1 -1
- package/dist/logic/iterateFieldsByAction.d.ts.map +1 -1
- package/dist/logic/schemaErrorLookup.d.ts.map +1 -1
- package/dist/logic/shouldRenderFormState.d.ts.map +1 -1
- package/dist/logic/skipValidation.d.ts +1 -4
- package/dist/logic/skipValidation.d.ts.map +1 -1
- package/dist/logic/unsetEmptyArray.d.ts +1 -1
- package/dist/logic/unsetEmptyArray.d.ts.map +1 -1
- package/dist/logic/updateFieldArrayRootError.d.ts.map +1 -1
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +767 -340
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/errors.d.ts +9 -4
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/fieldArray.d.ts +25 -1
- package/dist/types/fieldArray.d.ts.map +1 -1
- package/dist/types/fields.d.ts +1 -0
- package/dist/types/fields.d.ts.map +1 -1
- package/dist/types/form.d.ts +152 -57
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/path/common.d.ts +6 -0
- package/dist/types/path/common.d.ts.map +1 -1
- package/dist/types/path/eager.d.ts +16 -12
- package/dist/types/path/eager.d.ts.map +1 -1
- package/dist/types/utils.d.ts +30 -5
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/validator.d.ts +1 -1
- package/dist/types/validator.d.ts.map +1 -1
- package/dist/types/watch.d.ts +1 -1
- package/dist/types/watch.d.ts.map +1 -1
- package/dist/useController.d.ts +5 -17
- package/dist/useController.d.ts.map +1 -1
- package/dist/useFieldArray.d.ts +5 -30
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/useForm.d.ts +7 -22
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useFormContext.d.ts +11 -47
- package/dist/useFormContext.d.ts.map +1 -1
- package/dist/useFormState.d.ts +4 -23
- package/dist/useFormState.d.ts.map +1 -1
- package/dist/useIsomorphicLayoutEffect.d.ts.map +1 -1
- package/dist/useResyncOnReconnect.d.ts +5 -0
- package/dist/useResyncOnReconnect.d.ts.map +1 -0
- package/dist/useWatch.d.ts +7 -140
- package/dist/useWatch.d.ts.map +1 -1
- package/dist/utils/cloneObject.d.ts.map +1 -1
- package/dist/utils/deepEqual.d.ts +1 -1
- package/dist/utils/deepEqual.d.ts.map +1 -1
- package/dist/utils/flatten.d.ts.map +1 -1
- package/dist/utils/formData.d.ts +3 -0
- package/dist/utils/formData.d.ts.map +1 -0
- package/dist/utils/get.d.ts.map +1 -1
- package/dist/utils/has.d.ts +3 -0
- package/dist/utils/has.d.ts.map +1 -0
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/isKey.d.ts.map +1 -1
- package/dist/utils/json.d.ts +9 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/set.d.ts.map +1 -1
- package/dist/utils/stringToPath.d.ts.map +1 -1
- package/dist/utils/unset.d.ts.map +1 -1
- package/dist/utils/updateMethodsReference.d.ts.map +1 -1
- package/dist/watch.d.ts +4 -16
- package/dist/watch.d.ts.map +1 -1
- package/package.json +30 -27
- package/dist/formStateSubscribe.d.ts +0 -7
- package/dist/formStateSubscribe.d.ts.map +0 -1
- package/dist/logic/getFieldArrayParentNames.d.ts.map +0 -1
- package/dist/logic/getNodeParentName.d.ts +0 -3
- package/dist/logic/getNodeParentName.d.ts.map +0 -1
- package/dist/utils/deepMerge.d.ts +0 -2
- package/dist/utils/deepMerge.d.ts.map +0 -1
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FieldValues, InternalFieldName, Ref } from './fields';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FieldPath, FieldPathValue } from './path';
|
|
3
|
+
import type { BrowserNativeObject, IsAny, LiteralUnion, Merge, OpaqueType } from './utils';
|
|
3
4
|
import type { RegisterOptions, ValidateResult } from './validator';
|
|
4
5
|
export type Message = string;
|
|
5
6
|
export type MultipleFieldErrors = {
|
|
@@ -19,19 +20,23 @@ export type ErrorOption = {
|
|
|
19
20
|
type?: LiteralUnion<keyof RegisterOptions, string>;
|
|
20
21
|
types?: MultipleFieldErrors;
|
|
21
22
|
};
|
|
22
|
-
export type DeepRequired<T> = T extends BrowserNativeObject | Blob ? T : {
|
|
23
|
+
export type DeepRequired<T> = T extends BrowserNativeObject | Blob | OpaqueType ? T : {
|
|
23
24
|
[K in keyof T]-?: NonNullable<DeepRequired<T[K]>>;
|
|
24
25
|
};
|
|
25
26
|
export type FieldErrorsImpl<T extends FieldValues = FieldValues> = {
|
|
26
|
-
[K in keyof T]?: T[K] extends BrowserNativeObject | Blob ? FieldError : K extends 'root' | `root.${string}` ? GlobalError : T[K] extends object ? Merge<FieldError, FieldErrorsImpl<T[K]>> : FieldError;
|
|
27
|
+
[K in keyof T]?: T[K] extends BrowserNativeObject | Blob | OpaqueType ? FieldError : K extends 'root' | `root.${string}` ? GlobalError : T[K] extends object ? Merge<FieldError, FieldErrorsImpl<T[K]>> : FieldError;
|
|
27
28
|
};
|
|
28
29
|
export type GlobalError = Partial<{
|
|
29
30
|
type: string | number;
|
|
30
31
|
message: Message;
|
|
31
32
|
}>;
|
|
32
|
-
export type FieldErrors<T extends FieldValues = FieldValues> = Partial<
|
|
33
|
+
export type FieldErrors<T extends FieldValues = FieldValues> = Partial<FieldErrorsImpl<DeepRequired<T>>> & {
|
|
33
34
|
root?: Record<string, GlobalError> & GlobalError;
|
|
34
35
|
form?: GlobalError;
|
|
35
36
|
};
|
|
37
|
+
/** Resolves the error type stored by {@link FieldErrors} for a field path. */
|
|
38
|
+
export type FieldPathError<TFieldValues extends FieldValues, TFieldPath extends FieldPath<TFieldValues>> = TFieldPath extends FieldPath<TFieldValues> ? TFieldPath extends `${string}.root` ? GlobalError : DeepRequired<NonNullable<FieldPathValue<TFieldValues, TFieldPath>>> extends infer TFieldValue ? IsAny<TFieldValue> extends true ? FieldError : NonNullable<FieldErrorsImpl<{
|
|
39
|
+
value: TFieldValue;
|
|
40
|
+
}>['value']> : never : never;
|
|
36
41
|
export type InternalFieldErrors = Partial<Record<InternalFieldName, FieldError>>;
|
|
37
42
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,EACV,mBAAmB,EACnB,KAAK,EACL,YAAY,EACZ,KAAK,EACL,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnE,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,mBAAmB,GAAG;KAC/B,CAAC,IAAI,MAAM,eAAe,CAAC,CAAC,EAAE,cAAc;CAC9C,GAAG;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;C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AC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,OAAO,CACpE,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CACjC,GAAG;IACF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,WAAW,CAAC;IACjD,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,WAAW,EAChC,UAAU,SAAS,SAAS,CAAC,YAAY,CAAC,IAE1C,UAAU,SAAS,SAAS,CAAC,YAAY,CAAC,GACtC,UAAU,SAAS,GAAG,MAAM,OAAO,GACjC,WAAW,GACX,YAAY,CACR,WAAW,CAAC,cAAc,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CACtD,SAAS,MAAM,WAAW,GAC3B,KAAK,CAAC,WAAW,CAAC,SAAS,IAAI,GAC7B,UAAU,GACV,WAAW,CAAC,eAAe,CAAC;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAC/D,KAAK,GACT,KAAK,CAAC;AAEZ,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC,MAAM,CAAC,iBAAiB,EAAE,UAAU,CAAC,CACtC,CAAC"}
|
|
@@ -9,6 +9,7 @@ export type UseFieldArrayProps<TFieldValues extends FieldValues = FieldValues, T
|
|
|
9
9
|
validate?: Validate<FieldArray<TFieldValues, TFieldArrayName>[], TFieldValues> | Record<string, Validate<FieldArray<TFieldValues, TFieldArrayName>[], TFieldValues>>;
|
|
10
10
|
} & Pick<RegisterOptions<TFieldValues>, 'maxLength' | 'minLength' | 'required'>;
|
|
11
11
|
shouldUnregister?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
* `useFieldArray` returned `fields` with unique id
|
|
@@ -189,6 +190,29 @@ export type UseFieldArrayReturn<TFieldValues extends FieldValues = FieldValues,
|
|
|
189
190
|
insert: UseFieldArrayInsert<TFieldValues, TFieldArrayName>;
|
|
190
191
|
update: UseFieldArrayUpdate<TFieldValues, TFieldArrayName>;
|
|
191
192
|
replace: UseFieldArrayReplace<TFieldValues, TFieldArrayName>;
|
|
192
|
-
fields: FieldArrayWithId<TFieldValues, TFieldArrayName, TKeyName>
|
|
193
|
+
fields: (FieldArrayWithId<TFieldValues, TFieldArrayName, TKeyName> & {
|
|
194
|
+
disabled?: boolean;
|
|
195
|
+
})[];
|
|
193
196
|
};
|
|
197
|
+
/**
|
|
198
|
+
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```tsx
|
|
202
|
+
* const { fields } = useFieldArray({
|
|
203
|
+
* name: 'test',
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* <FieldArray
|
|
207
|
+
* render={({ fields }) =>
|
|
208
|
+
* fields.map((field, index) => (
|
|
209
|
+
* <input key={field.id} {...register(`test.${index}.value`)} />
|
|
210
|
+
* ))
|
|
211
|
+
* }
|
|
212
|
+
* />
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export type FieldArrayProps<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = {
|
|
216
|
+
render: (fieldArray: UseFieldArrayReturn<TFieldValues, TFieldArrayName>) => React.ReactElement;
|
|
217
|
+
} & UseFieldArrayProps<TFieldValues, TFieldArrayName>;
|
|
194
218
|
//# sourceMappingURL=fieldArray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldArray.d.ts","sourceRoot":"","sources":["../../src/types/fieldArray.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,QA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AAC"}
|
package/dist/types/form.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { VALIDATION_MODE } from '../constants';
|
|
3
3
|
import type { Subject } from '../utils/createSubject';
|
|
4
|
-
import type { ErrorOption,
|
|
4
|
+
import type { ErrorOption, FieldErrors, FieldPathError, GlobalError } from './errors';
|
|
5
5
|
import type { EventType } from './events';
|
|
6
6
|
import type { FieldArray } from './fieldArray';
|
|
7
7
|
import type { FieldName, FieldRefs, FieldValue, FieldValues, InternalFieldName } from './fields';
|
|
@@ -28,7 +28,7 @@ export type ValidationModeFlags = {
|
|
|
28
28
|
isOnTouch: boolean;
|
|
29
29
|
};
|
|
30
30
|
export type CriteriaMode = 'firstError' | 'all';
|
|
31
|
-
export type SubmitHandler<T> = (data: T, event?: React.BaseSyntheticEvent) =>
|
|
31
|
+
export type SubmitHandler<T, TResult = unknown> = (data: T, event?: React.BaseSyntheticEvent) => TResult;
|
|
32
32
|
export type FormSubmitHandler<TTransformedValues> = (payload: {
|
|
33
33
|
data: TTransformedValues;
|
|
34
34
|
event?: React.BaseSyntheticEvent;
|
|
@@ -41,9 +41,11 @@ export type SetValueConfig = Partial<{
|
|
|
41
41
|
shouldValidate: boolean;
|
|
42
42
|
shouldDirty: boolean;
|
|
43
43
|
shouldTouch: boolean;
|
|
44
|
+
delayError: boolean;
|
|
44
45
|
}>;
|
|
45
46
|
export type TriggerConfig = Partial<{
|
|
46
47
|
shouldFocus: boolean;
|
|
48
|
+
shouldTouch: boolean;
|
|
47
49
|
}>;
|
|
48
50
|
export type ResetFieldConfig<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Partial<{
|
|
49
51
|
keepDirty: boolean;
|
|
@@ -141,13 +143,13 @@ export type UseFormRegisterReturn<TFieldName extends InternalFieldName = Interna
|
|
|
141
143
|
disabled?: boolean;
|
|
142
144
|
};
|
|
143
145
|
/**
|
|
144
|
-
*
|
|
146
|
+
* Registers a field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including in `useEffect`.
|
|
145
147
|
*
|
|
146
148
|
* @remarks
|
|
147
149
|
* [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)
|
|
148
150
|
*
|
|
149
|
-
* @param name -
|
|
150
|
-
* @param options -
|
|
151
|
+
* @param name - The path name to the form field value; name is required and unique.
|
|
152
|
+
* @param options - Register options including validation, disabled, unregister, value as, and dependent validation.
|
|
151
153
|
*
|
|
152
154
|
* @returns onChange, onBlur, name, ref, and native HTML validation attributes if browser validation is enabled.
|
|
153
155
|
*
|
|
@@ -178,13 +180,13 @@ export type SetFocusOptions = Partial<{
|
|
|
178
180
|
shouldSelect: boolean;
|
|
179
181
|
}>;
|
|
180
182
|
/**
|
|
181
|
-
*
|
|
183
|
+
* Sets focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.
|
|
182
184
|
*
|
|
183
185
|
* @remarks
|
|
184
186
|
* [API](https://react-hook-form.com/docs/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)
|
|
185
187
|
*
|
|
186
|
-
* @param name -
|
|
187
|
-
* @param options -
|
|
188
|
+
* @param name - The path name to the form field value.
|
|
189
|
+
* @param options - Input focus behavior options.
|
|
188
190
|
*
|
|
189
191
|
* @example
|
|
190
192
|
* ```tsx
|
|
@@ -212,7 +214,7 @@ export type UseFormGetValues<TFieldValues extends FieldValues> = {
|
|
|
212
214
|
* @remarks
|
|
213
215
|
* [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
|
|
214
216
|
*
|
|
215
|
-
* @returns
|
|
217
|
+
* @returns Form values.
|
|
216
218
|
*
|
|
217
219
|
* @example
|
|
218
220
|
* ```tsx
|
|
@@ -230,8 +232,8 @@ export type UseFormGetValues<TFieldValues extends FieldValues> = {
|
|
|
230
232
|
* @remarks
|
|
231
233
|
* [API](https://react-hook-form.com/docs/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
|
|
232
234
|
*
|
|
233
|
-
* @param name -
|
|
234
|
-
* @param config -
|
|
235
|
+
* @param name - The path name to the form field value.
|
|
236
|
+
* @param config - Return touched or dirty fields.
|
|
235
237
|
*
|
|
236
238
|
* @returns the single field value
|
|
237
239
|
*
|
|
@@ -267,15 +269,60 @@ export type UseFormGetValues<TFieldValues extends FieldValues> = {
|
|
|
267
269
|
*/
|
|
268
270
|
<TFieldNames extends FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames], config?: GetValuesConfig): [...FieldPathValues<TFieldValues, TFieldNames>];
|
|
269
271
|
};
|
|
272
|
+
export type ErrorNamespacePath = 'root' | `root.${string}` | 'form' | `form.${string}`;
|
|
273
|
+
/** Resolves the error type returned for a single `getErrors` path. */
|
|
274
|
+
export type GetErrorsResult<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> | ErrorNamespacePath> = TName extends 'root' ? (Record<string, GlobalError> & GlobalError) | undefined : TName extends ErrorNamespacePath ? GlobalError | undefined : TName extends FieldPath<TFieldValues> ? FieldPathError<TFieldValues, TName> | undefined : never;
|
|
275
|
+
/** Gets currently stored form errors without subscribing or running validation. */
|
|
276
|
+
export type UseFormGetErrors<TFieldValues extends FieldValues> = {
|
|
277
|
+
/**
|
|
278
|
+
* Get all currently stored form errors without subscribing or running validation.
|
|
279
|
+
*
|
|
280
|
+
* @returns Form errors.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```tsx
|
|
284
|
+
* const errors = getErrors();
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
(name?: undefined): FieldErrors<TFieldValues>;
|
|
288
|
+
/**
|
|
289
|
+
* Get a currently stored field or global error without subscribing or running validation.
|
|
290
|
+
*
|
|
291
|
+
* @param name - The path to the error.
|
|
292
|
+
*
|
|
293
|
+
* @returns The error at the given path.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```tsx
|
|
297
|
+
* const emailError = getErrors("email");
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
<TName extends FieldPath<TFieldValues> | ErrorNamespacePath>(name: TName): GetErrorsResult<TFieldValues, TName>;
|
|
301
|
+
/**
|
|
302
|
+
* Get currently stored errors for multiple paths without subscribing or running validation.
|
|
303
|
+
*
|
|
304
|
+
* @param names - An array of error paths.
|
|
305
|
+
*
|
|
306
|
+
* @returns Errors for the given paths in the same order.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```tsx
|
|
310
|
+
* const [emailError, nameError] = getErrors(["email", "name"]);
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
<TNames extends (FieldPath<TFieldValues> | ErrorNamespacePath)[]>(names: readonly [...TNames]): {
|
|
314
|
+
[K in keyof TNames]: GetErrorsResult<TFieldValues, TNames[K]>;
|
|
315
|
+
};
|
|
316
|
+
};
|
|
270
317
|
/**
|
|
271
|
-
* This method will return individual field states. It will be useful when you are trying to retrieve the nested value field state in a
|
|
318
|
+
* This method will return individual field states. It will be useful when you are trying to retrieve the nested value field state in a type-safe approach.
|
|
272
319
|
*
|
|
273
320
|
* @remarks
|
|
274
321
|
* [API](https://react-hook-form.com/docs/useform/getfieldstate) • [Demo](https://codesandbox.io/s/getfieldstate-jvekk)
|
|
275
322
|
*
|
|
276
|
-
* @param name -
|
|
323
|
+
* @param name - The path name to the form field value.
|
|
277
324
|
*
|
|
278
|
-
* @returns invalid, isDirty, isTouched, isValidating, and error object
|
|
325
|
+
* @returns invalid, isDirty, isTouched, isValidating, and error object.
|
|
279
326
|
*
|
|
280
327
|
* @example
|
|
281
328
|
* ```tsx
|
|
@@ -296,15 +343,15 @@ export type UseFormGetFieldState<TFieldValues extends FieldValues> = <TFieldName
|
|
|
296
343
|
isDirty: boolean;
|
|
297
344
|
isTouched: boolean;
|
|
298
345
|
isValidating: boolean;
|
|
299
|
-
error?:
|
|
346
|
+
error?: FieldPathError<TFieldValues, TFieldName>;
|
|
300
347
|
};
|
|
301
348
|
/**
|
|
302
|
-
* This method will allow you to subscribe to formState without component
|
|
349
|
+
* This method will allow you to subscribe to formState without a component re-rendering.
|
|
303
350
|
*
|
|
304
351
|
* @remarks
|
|
305
352
|
* [API](https://react-hook-form.com/docs/useform/subscribe) • [Demo](https://codesandbox.io/s/subscribe)
|
|
306
353
|
*
|
|
307
|
-
* @param options -
|
|
354
|
+
* @param options - Subscription options to which formState subscribes.
|
|
308
355
|
*
|
|
309
356
|
* @example
|
|
310
357
|
* ```tsx
|
|
@@ -330,12 +377,12 @@ export type UseFormSubscribe<TFieldValues extends FieldValues> = <TFieldNames ex
|
|
|
330
377
|
}) => () => void;
|
|
331
378
|
export type UseFormWatch<TFieldValues extends FieldValues> = {
|
|
332
379
|
/**
|
|
333
|
-
* Watch and subscribe to
|
|
380
|
+
* Watch and subscribe to all form updates and changes based on onChange, and trigger re-renders at the useForm level.
|
|
334
381
|
*
|
|
335
382
|
* @remarks
|
|
336
383
|
* [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)
|
|
337
384
|
*
|
|
338
|
-
* @returns
|
|
385
|
+
* @returns The entire form values.
|
|
339
386
|
*
|
|
340
387
|
* @example
|
|
341
388
|
* ```tsx
|
|
@@ -344,15 +391,41 @@ export type UseFormWatch<TFieldValues extends FieldValues> = {
|
|
|
344
391
|
*/
|
|
345
392
|
(): TFieldValues;
|
|
346
393
|
/**
|
|
347
|
-
* Watch and subscribe to
|
|
394
|
+
* Watch and subscribe to the entire form update/change via callback, outside of render.
|
|
348
395
|
*
|
|
349
396
|
* @remarks
|
|
350
397
|
* [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)
|
|
351
398
|
*
|
|
352
|
-
* @param
|
|
399
|
+
* @param callback - invoked with the latest form values whenever a relevant update occurs
|
|
353
400
|
* @param defaultValue - defaultValues for the entire form
|
|
354
401
|
*
|
|
355
|
-
* @returns
|
|
402
|
+
* @returns a subscription object; call `unsubscribe` to stop watching
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```tsx
|
|
406
|
+
* useEffect(() => {
|
|
407
|
+
* const { unsubscribe } = watch((value, { name, type }) => console.log(value, name, type));
|
|
408
|
+
* return () => unsubscribe();
|
|
409
|
+
* }, [watch]);
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
(callback: (value: TFieldValues, info: {
|
|
413
|
+
name?: FieldPath<TFieldValues>;
|
|
414
|
+
type?: EventType;
|
|
415
|
+
value?: unknown;
|
|
416
|
+
}) => void, defaultValue?: DeepPartial<TFieldValues>): {
|
|
417
|
+
unsubscribe: () => void;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Watch and subscribe to an array of fields used outside of render.
|
|
421
|
+
*
|
|
422
|
+
* @remarks
|
|
423
|
+
* [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)
|
|
424
|
+
*
|
|
425
|
+
* @param names - An array of field names.
|
|
426
|
+
* @param defaultValue - DefaultValues for the entire form.
|
|
427
|
+
*
|
|
428
|
+
* @returns An array of field values.
|
|
356
429
|
*
|
|
357
430
|
* @example
|
|
358
431
|
* ```tsx
|
|
@@ -369,7 +442,7 @@ export type UseFormWatch<TFieldValues extends FieldValues> = {
|
|
|
369
442
|
* @param name - the path name to the form field value.
|
|
370
443
|
* @param defaultValue - defaultValues for the entire form
|
|
371
444
|
*
|
|
372
|
-
* @returns
|
|
445
|
+
* @returns the single field value
|
|
373
446
|
*
|
|
374
447
|
* @example
|
|
375
448
|
* ```tsx
|
|
@@ -379,15 +452,15 @@ export type UseFormWatch<TFieldValues extends FieldValues> = {
|
|
|
379
452
|
<TFieldName extends FieldPath<TFieldValues>>(name: TFieldName, defaultValue?: FieldPathValue<TFieldValues, TFieldName>): FieldPathValue<TFieldValues, TFieldName>;
|
|
380
453
|
};
|
|
381
454
|
/**
|
|
382
|
-
*
|
|
455
|
+
* Triggers field or form validation.
|
|
383
456
|
*
|
|
384
457
|
* @remarks
|
|
385
458
|
* [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)
|
|
386
459
|
*
|
|
387
|
-
* @param name -
|
|
388
|
-
* @param options -
|
|
460
|
+
* @param name - Providing no argument will trigger the entire form validation; an array of field names will validate those fields, and a single field name will only trigger that field's validation.
|
|
461
|
+
* @param options - Should focus on the error field, and/or mark the triggered field(s) as touched.
|
|
389
462
|
*
|
|
390
|
-
* @returns
|
|
463
|
+
* @returns Validation result.
|
|
391
464
|
*
|
|
392
465
|
* @example
|
|
393
466
|
* ```tsx
|
|
@@ -404,12 +477,12 @@ export type UseFormWatch<TFieldValues extends FieldValues> = {
|
|
|
404
477
|
*/
|
|
405
478
|
export type UseFormTrigger<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: TriggerConfig) => Promise<boolean>;
|
|
406
479
|
/**
|
|
407
|
-
*
|
|
480
|
+
* Clears all form errors.
|
|
408
481
|
*
|
|
409
482
|
* @remarks
|
|
410
483
|
* [API](https://react-hook-form.com/docs/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)
|
|
411
484
|
*
|
|
412
|
-
* @param name -
|
|
485
|
+
* @param name - The path name to the form field value.
|
|
413
486
|
*
|
|
414
487
|
* @example
|
|
415
488
|
* Clear all errors
|
|
@@ -419,16 +492,16 @@ export type UseFormTrigger<TFieldValues extends FieldValues> = (name?: FieldPath
|
|
|
419
492
|
* clearErrors("name2"); // clear a single field error
|
|
420
493
|
* ```
|
|
421
494
|
*/
|
|
422
|
-
export type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[] |
|
|
495
|
+
export type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[] | ErrorNamespacePath) => void;
|
|
423
496
|
/**
|
|
424
|
-
*
|
|
497
|
+
* Sets a single field value, or a group of field values.
|
|
425
498
|
*
|
|
426
499
|
* @remarks
|
|
427
500
|
* [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)
|
|
428
501
|
*
|
|
429
|
-
* @param name -
|
|
430
|
-
* @param value -
|
|
431
|
-
* @param options -
|
|
502
|
+
* @param name - The path name to the form field value.
|
|
503
|
+
* @param value - Field value.
|
|
504
|
+
* @param options - Should validate or update form state.
|
|
432
505
|
*
|
|
433
506
|
* @example
|
|
434
507
|
* ```tsx
|
|
@@ -439,7 +512,7 @@ export type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: Field
|
|
|
439
512
|
* shouldDirty: true, // update dirty and dirty fields form state
|
|
440
513
|
* });
|
|
441
514
|
*
|
|
442
|
-
* // Update a group fields
|
|
515
|
+
* // Update a group of fields
|
|
443
516
|
* setValue('root', {
|
|
444
517
|
* a: 'test', // setValue('root.a', 'data')
|
|
445
518
|
* b: 'test1', // setValue('root.b', 'data')
|
|
@@ -452,18 +525,18 @@ export type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: Field
|
|
|
452
525
|
export type UseFormSetValue<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, value: FieldPathValue<TFieldValues, TFieldName>, options?: SetValueConfig) => void;
|
|
453
526
|
export type UseFormSetValues<TFieldValues extends FieldValues> = (value: Partial<TFieldValues> | ResetAction<TFieldValues>, options?: SetValueConfig) => void;
|
|
454
527
|
/**
|
|
455
|
-
*
|
|
528
|
+
* Sets an error for a field. When setting an error that is not associated with a field, a manual `clearErrors` call is required.
|
|
456
529
|
*
|
|
457
530
|
* @remarks
|
|
458
531
|
* [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)
|
|
459
532
|
*
|
|
460
|
-
* @param name -
|
|
461
|
-
* @param error -
|
|
462
|
-
* @param options -
|
|
533
|
+
* @param name - The path name to the form field value.
|
|
534
|
+
* @param error - An error object containing the type and an optional message.
|
|
535
|
+
* @param options - Whether or not to focus on the field.
|
|
463
536
|
*
|
|
464
537
|
* @example
|
|
465
538
|
* ```tsx
|
|
466
|
-
* //
|
|
539
|
+
* // When the error is not associated with any fields, `clearErrors` will need to be invoked to clear the error.
|
|
467
540
|
* const onSubmit = () => setError("serverError", { type: "server", message: "Error occurred"})
|
|
468
541
|
*
|
|
469
542
|
* <button onClick={() => setError("name", { type: "min" })} />
|
|
@@ -472,17 +545,17 @@ export type UseFormSetValues<TFieldValues extends FieldValues> = (value: Partial
|
|
|
472
545
|
* <button onClick={() => setError("name", { type: "max" }, { shouldFocus: true })} />
|
|
473
546
|
* ```
|
|
474
547
|
*/
|
|
475
|
-
export type UseFormSetError<TFieldValues extends FieldValues> = (name: FieldPath<TFieldValues> |
|
|
548
|
+
export type UseFormSetError<TFieldValues extends FieldValues> = (name: FieldPath<TFieldValues> | ErrorNamespacePath, error: ErrorOption, options?: {
|
|
476
549
|
shouldFocus: boolean;
|
|
477
550
|
}) => void;
|
|
478
551
|
/**
|
|
479
|
-
*
|
|
552
|
+
* Unregisters a field reference and removes its value.
|
|
480
553
|
*
|
|
481
554
|
* @remarks
|
|
482
555
|
* [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)
|
|
483
556
|
*
|
|
484
|
-
* @param name -
|
|
485
|
-
* @param options -
|
|
557
|
+
* @param name - The path name to the form field value.
|
|
558
|
+
* @param options - Keep form state options.
|
|
486
559
|
*
|
|
487
560
|
* @example
|
|
488
561
|
* ```tsx
|
|
@@ -499,15 +572,15 @@ export type UseFormUnregister<TFieldValues extends FieldValues> = (name?: FieldP
|
|
|
499
572
|
keepError?: boolean;
|
|
500
573
|
}) => void;
|
|
501
574
|
/**
|
|
502
|
-
*
|
|
575
|
+
* Validates the entire form. Handles the submit and error callbacks.
|
|
503
576
|
*
|
|
504
577
|
* @remarks
|
|
505
578
|
* [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)
|
|
506
579
|
*
|
|
507
|
-
* @param onValid -
|
|
508
|
-
* @param onInvalid -
|
|
580
|
+
* @param onValid - Callback function invoked after the form passes validation.
|
|
581
|
+
* @param onInvalid - Callback function invoked when the form fails validation.
|
|
509
582
|
*
|
|
510
|
-
* @returns
|
|
583
|
+
* @returns Callback function.
|
|
511
584
|
*
|
|
512
585
|
* @example
|
|
513
586
|
* ```tsx
|
|
@@ -517,15 +590,15 @@ export type UseFormUnregister<TFieldValues extends FieldValues> = (name?: FieldP
|
|
|
517
590
|
* <form onSubmit={handleSubmit(onSubmit, onError)} />
|
|
518
591
|
* ```
|
|
519
592
|
*/
|
|
520
|
-
export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues = TFieldValues> = (onValid: SubmitHandler<TTransformedValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<
|
|
593
|
+
export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues = TFieldValues> = <TResult>(onValid: SubmitHandler<TTransformedValues, TResult>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<Awaited<TResult> | undefined>;
|
|
521
594
|
/**
|
|
522
|
-
*
|
|
595
|
+
* Resets a field's state and reference.
|
|
523
596
|
*
|
|
524
597
|
* @remarks
|
|
525
598
|
* [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)
|
|
526
599
|
*
|
|
527
|
-
* @param name -
|
|
528
|
-
* @param options -
|
|
600
|
+
* @param name - The path name to the form field value.
|
|
601
|
+
* @param options - Keep form state options.
|
|
529
602
|
*
|
|
530
603
|
* @example
|
|
531
604
|
* ```tsx
|
|
@@ -536,25 +609,25 @@ export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedVa
|
|
|
536
609
|
export type UseFormResetField<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: ResetFieldConfig<TFieldValues, TFieldName>) => void;
|
|
537
610
|
type ResetAction<TFieldValues> = (formValues: TFieldValues) => TFieldValues;
|
|
538
611
|
/**
|
|
539
|
-
*
|
|
612
|
+
* Resets the entire form state.
|
|
540
613
|
*
|
|
541
614
|
* @remarks
|
|
542
615
|
* [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)
|
|
543
616
|
*
|
|
544
|
-
* @param values -
|
|
545
|
-
* @param keepStateOptions -
|
|
617
|
+
* @param values - The entire form values to be reset.
|
|
618
|
+
* @param keepStateOptions - Keep form state options.
|
|
546
619
|
*
|
|
547
620
|
* @example
|
|
548
621
|
* ```tsx
|
|
549
622
|
* useEffect(() => {
|
|
550
|
-
* // reset the entire form after component mount or form defaultValues
|
|
623
|
+
* // reset the entire form after component mount or form defaultValues are ready
|
|
551
624
|
* reset({
|
|
552
625
|
* fieldA: "test"
|
|
553
626
|
* fieldB: "test"
|
|
554
627
|
* });
|
|
555
628
|
* }, [reset])
|
|
556
629
|
*
|
|
557
|
-
* //
|
|
630
|
+
* // Reset by combining with existing form values
|
|
558
631
|
* reset({
|
|
559
632
|
* ...getValues(),
|
|
560
633
|
* fieldB: "test"
|
|
@@ -570,6 +643,25 @@ type ResetAction<TFieldValues> = (formValues: TFieldValues) => TFieldValues;
|
|
|
570
643
|
* ```
|
|
571
644
|
*/
|
|
572
645
|
export type UseFormReset<TFieldValues extends FieldValues> = (values?: DefaultValues<TFieldValues> | TFieldValues | ResetAction<TFieldValues>, keepStateOptions?: KeepStateOptions) => void;
|
|
646
|
+
/**
|
|
647
|
+
* Resets the default values of the form and recomputes `dirtyFields`/`isDirty` without changing user values.
|
|
648
|
+
*
|
|
649
|
+
* @remarks
|
|
650
|
+
* [API](https://react-hook-form.com/docs/useform/resetdefaultvalues)
|
|
651
|
+
*
|
|
652
|
+
* @param values - The new default values.
|
|
653
|
+
* @param options - Options to keep dirty or isValid state.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```tsx
|
|
657
|
+
* // After a successful submission, update defaults to the submitted values
|
|
658
|
+
* // so that dirtyFields/isDirty reflect changes made after that point.
|
|
659
|
+
* const onSuccess = () => {
|
|
660
|
+
* resetDefaultValues(submittedValues);
|
|
661
|
+
* };
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
export type UseFormResetDefaultValues<TFieldValues extends FieldValues> = (values: DefaultValues<TFieldValues> | TFieldValues, options?: Partial<Pick<KeepStateOptions, 'keepDirty' | 'keepIsValid'>>) => void;
|
|
573
665
|
export type WatchInternal<TFieldValues> = (fieldNames?: InternalFieldName | InternalFieldName[], defaultValue?: DeepPartial<TFieldValues>, isMounted?: boolean, isGlobal?: boolean) => FieldPathValue<FieldValues, InternalFieldName> | FieldPathValues<FieldValues, InternalFieldName[]>;
|
|
574
666
|
export type GetIsDirty = <TName extends InternalFieldName, TData>(name?: TName, data?: TData) => boolean;
|
|
575
667
|
export type FormStateSubjectRef<TFieldValues extends FieldValues> = Subject<Partial<FormState<TFieldValues>> & {
|
|
@@ -615,6 +707,7 @@ export type Control<TFieldValues extends FieldValues = FieldValues, TContext = a
|
|
|
615
707
|
_state: {
|
|
616
708
|
mount: boolean;
|
|
617
709
|
action: boolean;
|
|
710
|
+
actionArrayLengths: Map<InternalFieldName, number>;
|
|
618
711
|
watch: boolean;
|
|
619
712
|
};
|
|
620
713
|
_reset: UseFormReset<TFieldValues>;
|
|
@@ -651,6 +744,7 @@ export type Control<TFieldValues extends FieldValues = FieldValues, TContext = a
|
|
|
651
744
|
export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues> = {
|
|
652
745
|
watch: UseFormWatch<TFieldValues>;
|
|
653
746
|
getValues: UseFormGetValues<TFieldValues>;
|
|
747
|
+
getErrors: UseFormGetErrors<TFieldValues>;
|
|
654
748
|
getFieldState: UseFormGetFieldState<TFieldValues>;
|
|
655
749
|
setError: UseFormSetError<TFieldValues>;
|
|
656
750
|
clearErrors: UseFormClearErrors<TFieldValues>;
|
|
@@ -660,6 +754,7 @@ export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TConte
|
|
|
660
754
|
formState: FormState<TFieldValues>;
|
|
661
755
|
resetField: UseFormResetField<TFieldValues>;
|
|
662
756
|
reset: UseFormReset<TFieldValues>;
|
|
757
|
+
resetDefaultValues: UseFormResetDefaultValues<TFieldValues>;
|
|
663
758
|
handleSubmit: UseFormHandleSubmit<TFieldValues, TTransformedValues>;
|
|
664
759
|
unregister: UseFormUnregister<TFieldValues>;
|
|
665
760
|
control: Control<TFieldValues, TContext, TTransformedValues>;
|