UNPKG

react-hook-form

Version:

Performant, flexible and extensible forms library for React Hooks

1 lines 214 kB
{"version":3,"file":"index.esm.mjs","sources":["../src/utils/isCheckBoxInput.ts","../src/utils/isDateObject.ts","../src/utils/isNullOrUndefined.ts","../src/utils/isObject.ts","../src/logic/getEventValue.ts","../src/logic/getNodeParentName.ts","../src/logic/isNameInFieldArray.ts","../src/utils/isPlainObject.ts","../src/utils/isWeb.ts","../src/utils/cloneObject.ts","../src/utils/compact.ts","../src/utils/isUndefined.ts","../src/utils/get.ts","../src/utils/isBoolean.ts","../src/utils/isKey.ts","../src/utils/stringToPath.ts","../src/utils/set.ts","../src/constants.ts","../src/useFormContext.tsx","../src/logic/getProxyFormState.ts","../src/utils/isPrimitive.ts","../src/utils/deepEqual.ts","../src/useDeepEqualEffect.ts","../src/useFormState.ts","../src/utils/isString.ts","../src/logic/generateWatchOutput.ts","../src/useWatch.ts","../src/useController.ts","../src/controller.tsx","../src/utils/flatten.ts","../src/form.tsx","../src/logic/appendErrors.ts","../src/utils/convertToArrayPayload.ts","../src/utils/createSubject.ts","../src/utils/isEmptyObject.ts","../src/utils/isFileInput.ts","../src/utils/isFunction.ts","../src/utils/isHTMLElement.ts","../src/utils/isMultipleSelect.ts","../src/utils/isRadioInput.ts","../src/utils/isRadioOrCheckbox.ts","../src/utils/live.ts","../src/utils/unset.ts","../src/utils/objectHasFunction.ts","../src/logic/getDirtyFields.ts","../src/logic/getCheckboxValue.ts","../src/logic/getFieldValueAs.ts","../src/logic/getRadioValue.ts","../src/logic/getFieldValue.ts","../src/logic/getResolverOptions.ts","../src/utils/isRegex.ts","../src/logic/getRuleValue.ts","../src/logic/getValidationModes.ts","../src/logic/hasPromiseValidation.ts","../src/logic/hasValidation.ts","../src/logic/isWatched.ts","../src/logic/iterateFieldsByAction.ts","../src/logic/schemaErrorLookup.ts","../src/logic/shouldRenderFormState.ts","../src/logic/shouldSubscribeByName.ts","../src/logic/skipValidation.ts","../src/logic/unsetEmptyArray.ts","../src/logic/updateFieldArrayRootError.ts","../src/utils/isMessage.ts","../src/logic/getValidateError.ts","../src/logic/getValueAndMessage.ts","../src/logic/validateField.ts","../src/logic/createFormControl.ts","../src/logic/generateId.ts","../src/logic/getFocusFieldName.ts","../src/utils/append.ts","../src/utils/fillEmptyArray.ts","../src/utils/insert.ts","../src/utils/move.ts","../src/utils/prepend.ts","../src/utils/remove.ts","../src/utils/swap.ts","../src/utils/update.ts","../src/useFieldArray.ts","../src/useForm.ts"],"sourcesContent":["import { FieldElement } from '../types';\n\nexport default (element: FieldElement): element is HTMLInputElement =>\n element.type === 'checkbox';\n","export default (value: unknown): value is Date => value instanceof Date;\n","export default (value: unknown): value is null | undefined => value == null;\n","import isDateObject from './isDateObject';\nimport isNullOrUndefined from './isNullOrUndefined';\n\nexport const isObjectType = (value: unknown): value is object =>\n typeof value === 'object';\n\nexport default <T extends object>(value: unknown): value is T =>\n !isNullOrUndefined(value) &&\n !Array.isArray(value) &&\n isObjectType(value) &&\n !isDateObject(value);\n","import isCheckBoxInput from '../utils/isCheckBoxInput';\nimport isObject from '../utils/isObject';\n\ntype Event = { target: any };\n\nexport default (event: unknown) =>\n isObject(event) && (event as Event).target\n ? isCheckBoxInput((event as Event).target)\n ? (event as Event).target.checked\n : (event as Event).target.value\n : event;\n","export default (name: string) =>\n name.substring(0, name.search(/\\.\\d+(\\.|$)/)) || name;\n","import { InternalFieldName } from '../types';\n\nimport getNodeParentName from './getNodeParentName';\n\nexport default (names: Set<InternalFieldName>, name: InternalFieldName) =>\n names.has(getNodeParentName(name));\n","import isObject from './isObject';\n\nexport default (tempObject: object) => {\n const prototypeCopy =\n tempObject.constructor && tempObject.constructor.prototype;\n\n return (\n isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf')\n );\n};\n","export default typeof window !== 'undefined' &&\n typeof window.HTMLElement !== 'undefined' &&\n typeof document !== 'undefined';\n","import isObject from './isObject';\nimport isPlainObject from './isPlainObject';\nimport isWeb from './isWeb';\n\nexport default function cloneObject<T>(data: T): T {\n let copy: any;\n const isArray = Array.isArray(data);\n const isFileListInstance =\n typeof FileList !== 'undefined' ? data instanceof FileList : false;\n\n if (data instanceof Date) {\n copy = new Date(data);\n } else if (data instanceof Set) {\n copy = new Set(data);\n } else if (\n !(isWeb && (data instanceof Blob || isFileListInstance)) &&\n (isArray || isObject(data))\n ) {\n copy = isArray ? [] : {};\n\n if (!isArray && !isPlainObject(data)) {\n copy = data;\n } else {\n for (const key in data) {\n if (data.hasOwnProperty(key)) {\n copy[key] = cloneObject(data[key]);\n }\n }\n }\n } else {\n return data;\n }\n\n return copy;\n}\n","export default <TValue>(value: TValue[]) =>\n Array.isArray(value) ? value.filter(Boolean) : [];\n","export default (val: unknown): val is undefined => val === undefined;\n","import compact from './compact';\nimport isNullOrUndefined from './isNullOrUndefined';\nimport isObject from './isObject';\nimport isUndefined from './isUndefined';\n\nexport default <T>(\n object: T,\n path?: string | null,\n defaultValue?: unknown,\n): any => {\n if (!path || !isObject(object)) {\n return defaultValue;\n }\n\n const result = compact(path.split(/[,[\\].]+?/)).reduce(\n (result, key) =>\n isNullOrUndefined(result) ? result : result[key as keyof {}],\n object,\n );\n\n return isUndefined(result) || result === object\n ? isUndefined(object[path as keyof T])\n ? defaultValue\n : object[path as keyof T]\n : result;\n};\n","export default (value: unknown): value is boolean => typeof value === 'boolean';\n","export default (value: string) => /^\\w*$/.test(value);\n","import compact from './compact';\n\nexport default (input: string): string[] =>\n compact(input.replace(/[\"|']|\\]/g, '').split(/\\.|\\[/));\n","import { FieldPath, FieldValues } from '../types';\n\nimport isKey from './isKey';\nimport isObject from './isObject';\nimport stringToPath from './stringToPath';\n\nexport default (\n object: FieldValues,\n path: FieldPath<FieldValues>,\n value?: unknown,\n) => {\n let index = -1;\n const tempPath = isKey(path) ? [path] : stringToPath(path);\n const length = tempPath.length;\n const lastIndex = length - 1;\n\n while (++index < length) {\n const key = tempPath[index];\n let newValue = value;\n\n if (index !== lastIndex) {\n const objValue = object[key];\n newValue =\n isObject(objValue) || Array.isArray(objValue)\n ? objValue\n : !isNaN(+tempPath[index + 1])\n ? []\n : {};\n }\n\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n return;\n }\n\n object[key] = newValue;\n object = object[key];\n }\n};\n","export const EVENTS = {\n BLUR: 'blur',\n FOCUS_OUT: 'focusout',\n CHANGE: 'change',\n} as const;\n\nexport const VALIDATION_MODE = {\n onBlur: 'onBlur',\n onChange: 'onChange',\n onSubmit: 'onSubmit',\n onTouched: 'onTouched',\n all: 'all',\n} as const;\n\nexport const INPUT_VALIDATION_RULES = {\n max: 'max',\n min: 'min',\n maxLength: 'maxLength',\n minLength: 'minLength',\n pattern: 'pattern',\n required: 'required',\n validate: 'validate',\n} as const;\n","import React from 'react';\n\nimport { FieldValues, FormProviderProps, UseFormReturn } from './types';\n\nconst HookFormContext = React.createContext<UseFormReturn | null>(null);\n\n/**\n * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)\n *\n * @returns return all useForm methods\n *\n * @example\n * ```tsx\n * function App() {\n * const methods = useForm();\n * const onSubmit = data => console.log(data);\n *\n * return (\n * <FormProvider {...methods} >\n * <form onSubmit={methods.handleSubmit(onSubmit)}>\n * <NestedInput />\n * <input type=\"submit\" />\n * </form>\n * </FormProvider>\n * );\n * }\n *\n * function NestedInput() {\n * const { register } = useFormContext(); // retrieve all hook methods\n * return <input {...register(\"test\")} />;\n * }\n * ```\n */\nexport const useFormContext = <\n TFieldValues extends FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(): UseFormReturn<TFieldValues, TContext, TTransformedValues> =>\n React.useContext(HookFormContext) as UseFormReturn<\n TFieldValues,\n TContext,\n TTransformedValues\n >;\n\n/**\n * A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)\n *\n * @param props - all useForm methods\n *\n * @example\n * ```tsx\n * function App() {\n * const methods = useForm();\n * const onSubmit = data => console.log(data);\n *\n * return (\n * <FormProvider {...methods} >\n * <form onSubmit={methods.handleSubmit(onSubmit)}>\n * <NestedInput />\n * <input type=\"submit\" />\n * </form>\n * </FormProvider>\n * );\n * }\n *\n * function NestedInput() {\n * const { register } = useFormContext(); // retrieve all hook methods\n * return <input {...register(\"test\")} />;\n * }\n * ```\n */\nexport const FormProvider = <\n TFieldValues extends FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n props: FormProviderProps<TFieldValues, TContext, TTransformedValues>,\n) => {\n const { children, ...data } = props;\n return (\n <HookFormContext.Provider value={data as unknown as UseFormReturn}>\n {children}\n </HookFormContext.Provider>\n );\n};\n","import { VALIDATION_MODE } from '../constants';\nimport { Control, FieldValues, FormState, ReadFormState } from '../types';\n\nexport default <\n TFieldValues extends FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(\n formState: FormState<TFieldValues>,\n control: Control<TFieldValues, TContext, TTransformedValues>,\n localProxyFormState?: ReadFormState,\n isRoot = true,\n) => {\n const result = {\n defaultValues: control._defaultValues,\n } as typeof formState;\n\n for (const key in formState) {\n Object.defineProperty(result, key, {\n get: () => {\n const _key = key as keyof FormState<TFieldValues> & keyof ReadFormState;\n\n if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {\n control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;\n }\n\n localProxyFormState && (localProxyFormState[_key] = true);\n return formState[_key];\n },\n });\n }\n\n return result;\n};\n","import { Primitive } from '../types';\n\nimport isNullOrUndefined from './isNullOrUndefined';\nimport { isObjectType } from './isObject';\n\nexport default (value: unknown): value is Primitive =>\n isNullOrUndefined(value) || !isObjectType(value);\n","import isObject from '../utils/isObject';\n\nimport isDateObject from './isDateObject';\nimport isPrimitive from './isPrimitive';\n\nexport default function deepEqual(object1: any, object2: any) {\n if (isPrimitive(object1) || isPrimitive(object2)) {\n return object1 === object2;\n }\n\n if (isDateObject(object1) && isDateObject(object2)) {\n return object1.getTime() === object2.getTime();\n }\n\n const keys1 = Object.keys(object1);\n const keys2 = Object.keys(object2);\n\n if (keys1.length !== keys2.length) {\n return false;\n }\n\n for (const key of keys1) {\n const val1 = object1[key];\n\n if (!keys2.includes(key)) {\n return false;\n }\n\n if (key !== 'ref') {\n const val2 = object2[key];\n\n if (\n (isDateObject(val1) && isDateObject(val2)) ||\n (isObject(val1) && isObject(val2)) ||\n (Array.isArray(val1) && Array.isArray(val2))\n ? !deepEqual(val1, val2)\n : val1 !== val2\n ) {\n return false;\n }\n }\n }\n\n return true;\n}\n","import { DependencyList, EffectCallback, useEffect, useRef } from 'react';\n\nimport deepEqual from './utils/deepEqual';\n\nexport const useDeepEqualEffect = <T extends DependencyList>(\n effect: EffectCallback,\n deps: T,\n) => {\n const ref = useRef<T>(deps);\n\n if (!deepEqual(deps, ref.current)) {\n ref.current = deps;\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(effect, ref.current);\n};\n","import React from 'react';\n\nimport getProxyFormState from './logic/getProxyFormState';\nimport {\n FieldValues,\n InternalFieldName,\n UseFormStateProps,\n UseFormStateReturn,\n} from './types';\nimport { useDeepEqualEffect } from './useDeepEqualEffect';\nimport { useFormContext } from './useFormContext';\n\n/**\n * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)\n *\n * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}\n *\n * @example\n * ```tsx\n * function App() {\n * const { register, handleSubmit, control } = useForm({\n * defaultValues: {\n * firstName: \"firstName\"\n * }});\n * const { dirtyFields } = useFormState({\n * control\n * });\n * const onSubmit = (data) => console.log(data);\n *\n * return (\n * <form onSubmit={handleSubmit(onSubmit)}>\n * <input {...register(\"firstName\")} placeholder=\"First Name\" />\n * {dirtyFields.firstName && <p>Field is dirty.</p>}\n * <input type=\"submit\" />\n * </form>\n * );\n * }\n * ```\n */\nexport function useFormState<\n TFieldValues extends FieldValues = FieldValues,\n TTransformedValues = TFieldValues,\n>(\n props?: UseFormStateProps<TFieldValues, TTransformedValues>,\n): UseFormStateReturn<TFieldValues> {\n const methods = useFormContext<TFieldValues, any, TTransformedValues>();\n const { control = methods.control, disabled, name, exact } = props || {};\n const [formState, updateFormState] = React.useState(control._formState);\n const _localProxyFormState = React.useRef({\n isDirty: false,\n isLoading: false,\n dirtyFields: false,\n touchedFields: false,\n validatingFields: false,\n isValidating: false,\n isValid: false,\n errors: false,\n });\n\n useDeepEqualEffect(\n () =>\n control._subscribe({\n name: name as InternalFieldName,\n formState: _localProxyFormState.current,\n exact,\n callback: (formState) => {\n !disabled &&\n updateFormState({\n ...control._formState,\n ...formState,\n });\n },\n }),\n [name, disabled, exact],\n );\n\n React.useEffect(() => {\n _localProxyFormState.current.isValid && control._setValid(true);\n }, [control]);\n\n return React.useMemo(\n () =>\n getProxyFormState(\n formState,\n control,\n _localProxyFormState.current,\n false,\n ),\n [formState, control],\n );\n}\n","export default (value: unknown): value is string => typeof value === 'string';\n","import { DeepPartial, FieldValues, Names } from '../types';\nimport get from '../utils/get';\nimport isString from '../utils/isString';\n\nexport default <T>(\n names: string | string[] | undefined,\n _names: Names,\n formValues?: FieldValues,\n isGlobal?: boolean,\n defaultValue?: DeepPartial<T> | unknown,\n) => {\n if (isString(names)) {\n isGlobal && _names.watch.add(names);\n return get(formValues, names, defaultValue);\n }\n\n if (Array.isArray(names)) {\n return names.map(\n (fieldName) => (\n isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)\n ),\n );\n }\n\n isGlobal && (_names.watchAll = true);\n\n return formValues;\n};\n","import React from 'react';\n\nimport generateWatchOutput from './logic/generateWatchOutput';\nimport {\n Control,\n DeepPartialSkipArrayKey,\n FieldPath,\n FieldPathValue,\n FieldPathValues,\n FieldValues,\n InternalFieldName,\n UseWatchProps,\n} from './types';\nimport { useDeepEqualEffect } from './useDeepEqualEffect';\nimport { useFormContext } from './useFormContext';\n\n/**\n * Subscribe to the entire form values change and re-render at the hook level.\n *\n * @remarks\n *\n * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)\n *\n * @param props - defaultValue, disable subscription and match exact name.\n *\n * @example\n * ```tsx\n * const { control } = useForm();\n * const values = useWatch({\n * control,\n * defaultValue: {\n * name: \"data\"\n * },\n * exact: false,\n * })\n * ```\n */\nexport function useWatch<\n TFieldValues extends FieldValues = FieldValues,\n TTransformedValues = TFieldValues,\n>(props: {\n defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;\n control?: Control<TFieldValues, any, TTransformedValues>;\n disabled?: boolean;\n exact?: boolean;\n}): DeepPartialSkipArrayKey<TFieldValues>;\n/**\n * Custom hook to subscribe to field change and isolate re-rendering at the component level.\n *\n * @remarks\n *\n * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)\n *\n * @param props - defaultValue, disable subscription and match exact name.\n *\n * @example\n * ```tsx\n * const { control } = useForm();\n * const values = useWatch({\n * control,\n * name: \"fieldA\",\n * defaultValue: \"default value\",\n * exact: false,\n * })\n * ```\n */\nexport function useWatch<\n TFieldValues extends FieldValues = FieldValues,\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n TTransformedValues = TFieldValues,\n>(props: {\n name: TFieldName;\n defaultValue?: FieldPathValue<TFieldValues, TFieldName>;\n control?: Control<TFieldValues, any, TTransformedValues>;\n disabled?: boolean;\n exact?: boolean;\n}): FieldPathValue<TFieldValues, TFieldName>;\n/**\n * Custom hook to subscribe to field change and isolate re-rendering at the component level.\n *\n * @remarks\n *\n * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)\n *\n * @param props - defaultValue, disable subscription and match exact name.\n *\n * @example\n * ```tsx\n * const { control } = useForm();\n * const values = useWatch({\n * control,\n * name: [\"fieldA\", \"fieldB\"],\n * defaultValue: {\n * fieldA: \"data\",\n * fieldB: \"data\"\n * },\n * exact: false,\n * })\n * ```\n */\nexport function useWatch<\n TFieldValues extends FieldValues = FieldValues,\n TFieldNames extends\n readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[],\n TTransformedValues = TFieldValues,\n>(props: {\n name: readonly [...TFieldNames];\n defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;\n control?: Control<TFieldValues, any, TTransformedValues>;\n disabled?: boolean;\n exact?: boolean;\n}): FieldPathValues<TFieldValues, TFieldNames>;\n/**\n * Custom hook to subscribe to field change and isolate re-rendering at the component level.\n *\n * @remarks\n *\n * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)\n *\n * @example\n * ```tsx\n * // can skip passing down the control into useWatch if the form is wrapped with the FormProvider\n * const values = useWatch()\n * ```\n */\nexport function useWatch<\n TFieldValues extends FieldValues = FieldValues,\n>(): DeepPartialSkipArrayKey<TFieldValues>;\n/**\n * Custom hook to subscribe to field change and isolate re-rendering at the component level.\n *\n * @remarks\n *\n * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)\n *\n * @example\n * ```tsx\n * const { control } = useForm();\n * const values = useWatch({\n * name: \"fieldName\"\n * control,\n * })\n * ```\n */\nexport function useWatch<TFieldValues extends FieldValues>(\n props?: UseWatchProps<TFieldValues>,\n) {\n const methods = useFormContext();\n const {\n control = methods.control,\n name,\n defaultValue,\n disabled,\n exact,\n } = props || {};\n\n const [value, updateValue] = React.useState(\n control._getWatch(\n name as InternalFieldName,\n defaultValue as DeepPartialSkipArrayKey<TFieldValues>,\n ),\n );\n\n useDeepEqualEffect(\n () =>\n control._subscribe({\n name: name as InternalFieldName,\n formState: {\n values: true,\n },\n exact,\n callback: (formState) =>\n !disabled &&\n updateValue(\n generateWatchOutput(\n name as InternalFieldName | InternalFieldName[],\n control._names,\n formState.values || control._formValues,\n false,\n defaultValue,\n ),\n ),\n }),\n [name, defaultValue, disabled, exact],\n );\n\n React.useEffect(() => control._removeUnmounted());\n\n return value;\n}\n","import React from 'react';\n\nimport getEventValue from './logic/getEventValue';\nimport isNameInFieldArray from './logic/isNameInFieldArray';\nimport cloneObject from './utils/cloneObject';\nimport get from './utils/get';\nimport isBoolean from './utils/isBoolean';\nimport isUndefined from './utils/isUndefined';\nimport set from './utils/set';\nimport { EVENTS } from './constants';\nimport {\n ControllerFieldState,\n Field,\n FieldPath,\n FieldPathValue,\n FieldValues,\n InternalFieldName,\n UseControllerProps,\n UseControllerReturn,\n} from './types';\nimport { useFormContext } from './useFormContext';\nimport { useFormState } from './useFormState';\nimport { useWatch } from './useWatch';\n\n/**\n * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)\n *\n * @param props - the path name to the form field value, and validation rules.\n *\n * @returns field properties, field and form state. {@link UseControllerReturn}\n *\n * @example\n * ```tsx\n * function Input(props) {\n * const { field, fieldState, formState } = useController(props);\n * return (\n * <div>\n * <input {...field} placeholder={props.name} />\n * <p>{fieldState.isTouched && \"Touched\"}</p>\n * <p>{formState.isSubmitted ? \"submitted\" : \"\"}</p>\n * </div>\n * );\n * }\n * ```\n */\nexport function useController<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n TTransformedValues = TFieldValues,\n>(\n props: UseControllerProps<TFieldValues, TName, TTransformedValues>,\n): UseControllerReturn<TFieldValues, TName> {\n const methods = useFormContext<TFieldValues, any, TTransformedValues>();\n const { name, disabled, control = methods.control, shouldUnregister } = props;\n const isArrayField = isNameInFieldArray(control._names.array, name);\n const value = useWatch({\n control,\n name,\n defaultValue: get(\n control._formValues,\n name,\n get(control._defaultValues, name, props.defaultValue),\n ),\n exact: true,\n }) as FieldPathValue<TFieldValues, TName>;\n const formState = useFormState({\n control,\n name,\n exact: true,\n });\n\n const _props = React.useRef(props);\n const _registerProps = React.useRef(\n control.register(name, {\n ...props.rules,\n value,\n ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),\n }),\n );\n\n const fieldState = React.useMemo(\n () =>\n Object.defineProperties(\n {},\n {\n invalid: {\n enumerable: true,\n get: () => !!get(formState.errors, name),\n },\n isDirty: {\n enumerable: true,\n get: () => !!get(formState.dirtyFields, name),\n },\n isTouched: {\n enumerable: true,\n get: () => !!get(formState.touchedFields, name),\n },\n isValidating: {\n enumerable: true,\n get: () => !!get(formState.validatingFields, name),\n },\n error: {\n enumerable: true,\n get: () => get(formState.errors, name),\n },\n },\n ) as ControllerFieldState,\n [formState, name],\n );\n\n const onChange = React.useCallback(\n (event: any) =>\n _registerProps.current.onChange({\n target: {\n value: getEventValue(event),\n name: name as InternalFieldName,\n },\n type: EVENTS.CHANGE,\n }),\n [name],\n );\n\n const onBlur = React.useCallback(\n () =>\n _registerProps.current.onBlur({\n target: {\n value: get(control._formValues, name),\n name: name as InternalFieldName,\n },\n type: EVENTS.BLUR,\n }),\n [name, control._formValues],\n );\n\n const ref = React.useCallback(\n (elm: any) => {\n const field = get(control._fields, name);\n\n if (field && elm) {\n field._f.ref = {\n focus: () => elm.focus(),\n select: () => elm.select(),\n setCustomValidity: (message: string) =>\n elm.setCustomValidity(message),\n reportValidity: () => elm.reportValidity(),\n };\n }\n },\n [control._fields, name],\n );\n\n const field = React.useMemo(\n () => ({\n name,\n value,\n ...(isBoolean(disabled) || formState.disabled\n ? { disabled: formState.disabled || disabled }\n : {}),\n onChange,\n onBlur,\n ref,\n }),\n [name, disabled, formState.disabled, onChange, onBlur, ref, value],\n );\n\n React.useEffect(() => {\n const _shouldUnregisterField =\n control._options.shouldUnregister || shouldUnregister;\n\n control.register(name, {\n ..._props.current.rules,\n ...(isBoolean(_props.current.disabled)\n ? { disabled: _props.current.disabled }\n : {}),\n });\n\n const updateMounted = (name: InternalFieldName, value: boolean) => {\n const field: Field = get(control._fields, name);\n\n if (field && field._f) {\n field._f.mount = value;\n }\n };\n\n updateMounted(name, true);\n\n if (_shouldUnregisterField) {\n const value = cloneObject(get(control._options.defaultValues, name));\n set(control._defaultValues, name, value);\n if (isUndefined(get(control._formValues, name))) {\n set(control._formValues, name, value);\n }\n }\n\n !isArrayField && control.register(name);\n\n return () => {\n (\n isArrayField\n ? _shouldUnregisterField && !control._state.action\n : _shouldUnregisterField\n )\n ? control.unregister(name)\n : updateMounted(name, false);\n };\n }, [name, control, isArrayField, shouldUnregister]);\n\n React.useEffect(() => {\n control._setDisabledField({\n disabled,\n name,\n });\n }, [disabled, name, control]);\n\n return React.useMemo(\n () => ({\n field,\n formState,\n fieldState,\n }),\n [field, formState, fieldState],\n );\n}\n","import { ControllerProps, FieldPath, FieldValues } from './types';\nimport { useController } from './useController';\n\n/**\n * Component based on `useController` hook to work with controlled component.\n *\n * @remarks\n * [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)\n *\n * @param props - the path name to the form field value, and validation rules.\n *\n * @returns provide field handler functions, field and form state.\n *\n * @example\n * ```tsx\n * function App() {\n * const { control } = useForm<FormValues>({\n * defaultValues: {\n * test: \"\"\n * }\n * });\n *\n * return (\n * <form>\n * <Controller\n * control={control}\n * name=\"test\"\n * render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (\n * <>\n * <input\n * onChange={onChange} // send value to hook form\n * onBlur={onBlur} // notify when input is touched\n * value={value} // return updated value\n * ref={ref} // set ref for focus management\n * />\n * <p>{formState.isSubmitted ? \"submitted\" : \"\"}</p>\n * <p>{fieldState.isTouched ? \"touched\" : \"\"}</p>\n * </>\n * )}\n * />\n * </form>\n * );\n * }\n * ```\n */\nconst Controller = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n TTransformedValues = TFieldValues,\n>(\n props: ControllerProps<TFieldValues, TName, TTransformedValues>,\n) =>\n props.render(useController<TFieldValues, TName, TTransformedValues>(props));\n\nexport { Controller };\n","import { FieldValues } from '../types';\n\nimport { isObjectType } from './isObject';\n\nexport const flatten = (obj: FieldValues) => {\n const output: FieldValues = {};\n\n for (const key of Object.keys(obj)) {\n if (isObjectType(obj[key]) && obj[key] !== null) {\n const nested = flatten(obj[key]);\n\n for (const nestedKey of Object.keys(nested)) {\n output[`${key}.${nestedKey}`] = nested[nestedKey];\n }\n } else {\n output[key] = obj[key];\n }\n }\n\n return output;\n};\n","import React from 'react';\n\nimport { flatten } from './utils/flatten';\nimport { FieldValues, FormProps } from './types';\nimport { useFormContext } from './useFormContext';\n\nconst POST_REQUEST = 'post';\n\n/**\n * Form component to manage submission.\n *\n * @param props - to setup submission detail. {@link FormProps}\n *\n * @returns form component or headless render prop.\n *\n * @example\n * ```tsx\n * function App() {\n * const { control, formState: { errors } } = useForm();\n *\n * return (\n * <Form action=\"/api\" control={control}>\n * <input {...register(\"name\")} />\n * <p>{errors?.root?.server && 'Server error'}</p>\n * <button>Submit</button>\n * </Form>\n * );\n * }\n * ```\n */\nfunction Form<\n TFieldValues extends FieldValues,\n TTransformedValues = TFieldValues,\n>(props: FormProps<TFieldValues, TTransformedValues>) {\n const methods = useFormContext<TFieldValues, any, TTransformedValues>();\n const [mounted, setMounted] = React.useState(false);\n const {\n control = methods.control,\n onSubmit,\n children,\n action,\n method = POST_REQUEST,\n headers,\n encType,\n onError,\n render,\n onSuccess,\n validateStatus,\n ...rest\n } = props;\n\n const submit = async (event?: React.BaseSyntheticEvent) => {\n let hasError = false;\n let type = '';\n\n await control.handleSubmit(async (data) => {\n const formData = new FormData();\n let formDataJson = '';\n\n try {\n formDataJson = JSON.stringify(data);\n } catch {}\n\n const flattenFormValues = flatten(control._formValues);\n\n for (const key in flattenFormValues) {\n formData.append(key, flattenFormValues[key]);\n }\n\n if (onSubmit) {\n await onSubmit({\n data,\n event,\n method,\n formData,\n formDataJson,\n });\n }\n\n if (action) {\n try {\n const shouldStringifySubmissionData = [\n headers && headers['Content-Type'],\n encType,\n ].some((value) => value && value.includes('json'));\n\n const response = await fetch(String(action), {\n method,\n headers: {\n ...headers,\n ...(encType ? { 'Content-Type': encType } : {}),\n },\n body: shouldStringifySubmissionData ? formDataJson : formData,\n });\n\n if (\n response &&\n (validateStatus\n ? !validateStatus(response.status)\n : response.status < 200 || response.status >= 300)\n ) {\n hasError = true;\n onError && onError({ response });\n type = String(response.status);\n } else {\n onSuccess && onSuccess({ response });\n }\n } catch (error: unknown) {\n hasError = true;\n onError && onError({ error });\n }\n }\n })(event);\n\n if (hasError && props.control) {\n props.control._subjects.state.next({\n isSubmitSuccessful: false,\n });\n props.control.setError('root.server', {\n type,\n });\n }\n };\n\n React.useEffect(() => {\n setMounted(true);\n }, []);\n\n return render ? (\n <>\n {render({\n submit,\n })}\n </>\n ) : (\n <form\n noValidate={mounted}\n action={action}\n method={method}\n encType={encType}\n onSubmit={submit}\n {...rest}\n >\n {children}\n </form>\n );\n}\n\nexport { Form };\n","import {\n InternalFieldErrors,\n InternalFieldName,\n ValidateResult,\n} from '../types';\n\nexport default (\n name: InternalFieldName,\n validateAllFieldCriteria: boolean,\n errors: InternalFieldErrors,\n type: string,\n message: ValidateResult,\n) =>\n validateAllFieldCriteria\n ? {\n ...errors[name],\n types: {\n ...(errors[name] && errors[name]!.types ? errors[name]!.types : {}),\n [type]: message || true,\n },\n }\n : {};\n","export default <T>(value: T) => (Array.isArray(value) ? value : [value]);\n","import { Noop } from '../types';\n\nexport type Observer<T> = {\n next: (value: T) => void;\n};\n\nexport type Subscription = {\n unsubscribe: Noop;\n};\n\nexport type Subject<T> = {\n readonly observers: Observer<T>[];\n subscribe: (value: Observer<T>) => Subscription;\n unsubscribe: Noop;\n} & Observer<T>;\n\nexport default <T>(): Subject<T> => {\n let _observers: Observer<T>[] = [];\n\n const next = (value: T) => {\n for (const observer of _observers) {\n observer.next && observer.next(value);\n }\n };\n\n const subscribe = (observer: Observer<T>): Subscription => {\n _observers.push(observer);\n return {\n unsubscribe: () => {\n _observers = _observers.filter((o) => o !== observer);\n },\n };\n };\n\n const unsubscribe = () => {\n _observers = [];\n };\n\n return {\n get observers() {\n return _observers;\n },\n next,\n subscribe,\n unsubscribe,\n };\n};\n","import { EmptyObject } from '../types';\n\nimport isObject from './isObject';\n\nexport default (value: unknown): value is EmptyObject =>\n isObject(value) && !Object.keys(value).length;\n","import { FieldElement } from '../types';\n\nexport default (element: FieldElement): element is HTMLInputElement =>\n element.type === 'file';\n","export default (value: unknown): value is Function =>\n typeof value === 'function';\n","import isWeb from './isWeb';\n\nexport default (value: unknown): value is HTMLElement => {\n if (!isWeb) {\n return false;\n }\n\n const owner = value ? ((value as HTMLElement).ownerDocument as Document) : 0;\n return (\n value instanceof\n (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement)\n );\n};\n","import { FieldElement } from '../types';\n\nexport default (element: FieldElement): element is HTMLSelectElement =>\n element.type === `select-multiple`;\n","import { FieldElement } from '../types';\n\nexport default (element: FieldElement): element is HTMLInputElement =>\n element.type === 'radio';\n","import { FieldElement } from '../types';\n\nimport isCheckBoxInput from './isCheckBoxInput';\nimport isRadioInput from './isRadioInput';\n\nexport default (ref: FieldElement): ref is HTMLInputElement =>\n isRadioInput(ref) || isCheckBoxInput(ref);\n","import { Ref } from '../types';\n\nimport isHTMLElement from './isHTMLElement';\n\nexport default (ref: Ref) => isHTMLElement(ref) && ref.isConnected;\n","import isEmptyObject from './isEmptyObject';\nimport isKey from './isKey';\nimport isObject from './isObject';\nimport isUndefined from './isUndefined';\nimport stringToPath from './stringToPath';\n\nfunction baseGet(object: any, updatePath: (string | number)[]) {\n const length = updatePath.slice(0, -1).length;\n let index = 0;\n\n while (index < length) {\n object = isUndefined(object) ? index++ : object[updatePath[index++]];\n }\n\n return object;\n}\n\nfunction isEmptyArray(obj: unknown[]) {\n for (const key in obj) {\n if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {\n return false;\n }\n }\n return true;\n}\n\nexport default function unset(object: any, path: string | (string | number)[]) {\n const paths = Array.isArray(path)\n ? path\n : isKey(path)\n ? [path]\n : stringToPath(path);\n\n const childObject = paths.length === 1 ? object : baseGet(object, paths);\n\n const index = paths.length - 1;\n const key = paths[index];\n\n if (childObject) {\n delete childObject[key];\n }\n\n if (\n index !== 0 &&\n ((isObject(childObject) && isEmptyObject(childObject)) ||\n (Array.isArray(childObject) && isEmptyArray(childObject)))\n ) {\n unset(object, paths.slice(0, -1));\n }\n\n return object;\n}\n","import isFunction from './isFunction';\n\nexport default <T>(data: T): boolean => {\n for (const key in data) {\n if (isFunction(data[key])) {\n return true;\n }\n }\n return false;\n};\n","import deepEqual from '../utils/deepEqual';\nimport isNullOrUndefined from '../utils/isNullOrUndefined';\nimport isObject from '../utils/isObject';\nimport isPrimitive from '../utils/isPrimitive';\nimport isUndefined from '../utils/isUndefined';\nimport objectHasFunction from '../utils/objectHasFunction';\n\nfunction markFieldsDirty<T>(data: T, fields: Record<string, any> = {}) {\n const isParentNodeArray = Array.isArray(data);\n\n if (isObject(data) || isParentNodeArray) {\n for (const key in data) {\n if (\n Array.isArray(data[key]) ||\n (isObject(data[key]) && !objectHasFunction(data[key]))\n ) {\n fields[key] = Array.isArray(data[key]) ? [] : {};\n markFieldsDirty(data[key], fields[key]);\n } else if (!isNullOrUndefined(data[key])) {\n fields[key] = true;\n }\n }\n }\n\n return fields;\n}\n\nfunction getDirtyFieldsFromDefaultValues<T>(\n data: T,\n formValues: T,\n dirtyFieldsFromValues: Record<\n Extract<keyof T, string>,\n ReturnType<typeof markFieldsDirty> | boolean\n >,\n) {\n const isParentNodeArray = Array.isArray(data);\n\n if (isObject(data) || isParentNodeArray) {\n for (const key in data) {\n if (\n Array.isArray(data[key]) ||\n (isObject(data[key]) && !objectHasFunction(data[key]))\n ) {\n if (\n isUndefined(formValues) ||\n isPrimitive(dirtyFieldsFromValues[key])\n ) {\n dirtyFieldsFromValues[key] = Array.isArray(data[key])\n ? markFieldsDirty(data[key], [])\n : { ...markFieldsDirty(data[key]) };\n } else {\n getDirtyFieldsFromDefaultValues(\n data[key],\n isNullOrUndefined(formValues) ? {} : formValues[key],\n dirtyFieldsFromValues[key],\n );\n }\n } else {\n dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);\n }\n }\n }\n\n return dirtyFieldsFromValues;\n}\n\nexport default <T>(defaultValues: T, formValues: T) =>\n getDirtyFieldsFromDefaultValues(\n defaultValues,\n formValues,\n markFieldsDirty(formValues),\n );\n","import isUndefined from '../utils/isUndefined';\n\ntype CheckboxFieldResult = {\n isValid: boolean;\n value: string | string[] | boolean | undefined;\n};\n\nconst defaultResult: CheckboxFieldResult = {\n value: false,\n isValid: false,\n};\n\nconst validResult = { value: true, isValid: true };\n\nexport default (options?: HTMLInputElement[]): CheckboxFieldResult => {\n if (Array.isArray(options)) {\n if (options.length > 1) {\n const values = options\n .filter((option) => option && option.checked && !option.disabled)\n .map((option) => option.value);\n return { value: values, isValid: !!values.length };\n }\n\n return options[0].checked && !options[0].disabled\n ? // @ts-expect-error expected to work in the browser\n options[0].attributes && !isUndefined(options[0].attributes.value)\n ? isUndefined(options[0].value) || options[0].value === ''\n ? validResult\n : { value: options[0].value, isValid: true }\n : validResult\n : defaultResult;\n }\n\n return defaultResult;\n};\n","import { Field, NativeFieldValue } from '../types';\nimport isString from '../utils/isString';\nimport isUndefined from '../utils/isUndefined';\n\nexport default <T extends NativeFieldValue>(\n value: T,\n { valueAsNumber, valueAsDate, setValueAs }: Field['_f'],\n) =>\n isUndefined(value)\n ? value\n : valueAsNumber\n ? value === ''\n ? NaN\n : value\n ? +value\n : value\n : valueAsDate && isString(value)\n ? new Date(value)\n : setValueAs\n ? setValueAs(value)\n : value;\n","type RadioFieldResult = {\n isValid: boolean;\n value: number | string | null;\n};\n\nconst defaultReturn: RadioFieldResult = {\n isValid: false,\n value: null,\n};\n\nexport default (options?: HTMLInputElement[]): RadioFieldResult =>\n Array.isArray(options)\n ? options.reduce(\n (previous, option): RadioFieldResult =>\n option && option.checked && !option.disabled\n ? {\n isValid: true,\n value: option.value,\n }\n : previous,\n defaultReturn,\n )\n : defaultReturn;\n","import { Field } from '../types';\nimport isCheckBox from '../utils/isCheckBoxInput';\nimport isFileInput from '../utils/isFileInput';\nimport isMultipleSelect from '../utils/isMultipleSelect';\nimport isRadioInput from '../utils/isRadioInput';\nimport isUndefined from '../utils/isUndefined';\n\nimport getCheckboxValue from './getCheckboxValue';\nimport getFieldValueAs from './getFieldValueAs';\nimport getRadioValue from './getRadioValue';\n\nexport default function getFieldValue(_f: Field['_f']) {\n const ref = _f.ref;\n\n if (isFileInput(ref)) {\n return ref.files;\n }\n\n if (isRadioInput(ref)) {\n return getRadioValue(_f.refs).value;\n }\n\n if (isMultipleSelect(ref)) {\n return [...ref.selectedOptions].map(({ value }) => value);\n }\n\n if (isCheckBox(ref)) {\n return getCheckboxValue(_f.refs).value;\n }\n\n return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);\n}\n","import {\n CriteriaMode,\n Field,\n FieldName,\n FieldRefs,\n FieldValues,\n InternalFieldName,\n} from '../types';\nimport { get } from '../utils';\nimport set from '../utils/set';\n\nexport default <TFieldValues extends FieldValues>(\n fieldsNames: Set<InternalFieldName> | InternalFieldName[],\n _fields: FieldRefs,\n criteriaMode?: CriteriaMode,\n shouldUseNativeValidation?: boolean | undefined,\n) => {\n const fields: Record<InternalFieldName, Field['_f']> = {};\n\n for (const name of fieldsNames) {\n const field: Field = get(_fields, name);\n\n field && set(fields, name, field._f);\n }\n\n return {\n criteriaMode,\n names: [...fieldsNames] as FieldName<TFieldValues>[],\n fields,\n shouldUseNativeValidation,\n };\n};\n","export default (value: unknown): value is RegExp => value instanceof RegExp;\n","import {\n ValidationRule,\n ValidationValue,\n ValidationValueMessage,\n} from '../types';\nimport isObject from '../utils/isObject';\nimport isRegex from '../utils/isRegex';\nimport isUndefined from '../utils/isUndefined';\n\nexport default <T extends ValidationValue>(\n rule?: ValidationRule<T> | ValidationValueMessage<T>,\n) =>\n isUndefined(rule)\n ? rule\n : isRegex(rule)\n ? rule.source\n : isObject(rule)\n ? isRegex(rule.value)\n ? rule.value.source\n : rule.value\n : rule;\n","import { VALIDATION_MODE } from '../constants';\nimport { Mode, ValidationModeFlags } from '../types';\n\nexport default (mode?: Mode): ValidationModeFlags => ({\n isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,\n isOnBlur: mode === VALIDATION_MODE.onBlur,\n isOnChange: mode === VALIDATION_MODE.onChange,\n isOnAll: mode === VALIDATION_MODE.all,\n isOnTouch: mode === VALIDATION_MODE.onTouched,\n});\n","import { Field, Validate } from '../types';\nimport isFunction from '../utils/isFunction';\nimport isObject from '../utils/isObject';\n\nconst ASYNC_FUNCTION = 'AsyncFunction';\n\nexport default (fieldReference: Field['_f']) =>\n !!fieldReference &&\n !!fieldReference.validate &&\n !!(\n (isFunction(fieldReference.validate) &&\n fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||\n (isObject(fieldReference.validate) &&\n Object.values(fieldReference.validate).find(\n (validateFunction: Validate<unknown, unknown>) =>\n validateFunction.constructor.name === ASYNC_FUNCTION,\n ))\n );\n","import { Field } from '../types';\n\nexport default (options: Field['_f']) =>\n options.mount &&\n (options.required ||\n options.min ||\n options.max ||\n options.maxLength ||\n options.minLength ||\n options.pattern ||\n options.validate);\n","import { InternalFieldName, Names } from '../types';\n\nexport default (\n name: InternalFieldName,\n _names: Names,\n isBlurEvent?: boolean,\n) =>\n !isBlurEvent &&\n (_names.watchAll ||\n _names.watch.has(name) ||\n [..._names.watch].some(\n (watchName) =>\n name.startsWith(watchName) &&\n /^\\.\\w+/.test(name.slice(watchName.length)),\n ));\n","import { FieldRefs, InternalFieldName, Ref } from '../types';\nimport { get } from '../utils';\nimport isObject from '../utils/isObject';\n\nconst iterateFieldsByAction = (\n fields: FieldRefs,\n action: (ref: Ref, name: string) => 1 | undefined | void,\n fieldsNames?: Set<InternalFieldName> | InternalFieldName[] | 0,\n abortEarly?: boolean,\n) => {\n for (const key of fieldsNames || Object.keys(fields)) {\n const field = get(fields, key);\n\n if (field) {\n const { _f, ...currentField } = field;\n\n if (_f) {\n if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {\n return true;\n } else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {\n return true;\n } else {\n if (iterateFieldsByAction(currentField, action)) {\n break;\n }\n }\n } else if (isObject(currentField)) {\n if (iterateFieldsByAction(currentField as FieldRefs, action)) {\n break;\n }\n }\n }\n }\n return;\n};\nexport default iterateFieldsByAction;\n","import { FieldError, FieldErrors, FieldValues } from '../types';\nimport get from '../utils/get';\nimport isKey from '../utils/isKey';\n\nexport default function schemaErrorLookup<T extends FieldValues = FieldValues>(\n errors: FieldErrors<T>,\n _fields: FieldValues,\n name: string,\n): {\n error?: FieldError;\n name: string;\n} {\n const error = get(errors, name);\n\n if (error || isKey(name)) {\n return {\n error,\n name,\n };\n }\n\n const names = name.split('.');\n\n while (names.length) {\n const fieldName = names.join('.');\n const field = get(_fields, fieldName);\n const foundError = get(errors, fieldName);\n\n if (field && !Array.isArray(field) && name !== fieldName) {\n return { name };\n }\n\n if (foundError && foundError.type) {\n return {\n name: fieldName,\n error: foundError,\n };\n }\n\n names.pop();\n }\n\n return {\n name,\n };\n}\n","import { VALIDATION_MODE } from '../constants';\nimport {\n FieldValues,\n FormState,\n InternalFieldName,\n ReadFormState,\n} from '../types';\nimport isEmptyObject from '../utils/isEmptyObject';\n\nexport default <T extends FieldValues, K extends ReadFormState>(\n formStateData: Partial<FormState<T>> & {\n name?: InternalFieldName;\n values?: T;\n },\n _proxyFormState: K,\n updateFormState: (formState: Partial<FormState<T>>) => void,\n isRoot?: boolean,\n) => {\n updateFormStat