MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / createFormControl

Function createFormControl

src/logic/createFormControl.ts:107–1761  ·  view source on GitHub ↗
(
  props: UseFormProps<TFieldValues, TContext, TTransformedValues> = {},
)

Source from the content-addressed store, hash-verified

105} as const;
106
107export function createFormControl<
108 TFieldValues extends FieldValues = FieldValues,
109 TContext = any,
110 TTransformedValues = TFieldValues,
111>(
112 props: UseFormProps<TFieldValues, TContext, TTransformedValues> = {},
113): Omit<
114 UseFormReturn<TFieldValues, TContext, TTransformedValues>,
115 'formState'
116> & {
117 formControl: Omit<
118 UseFormReturn<TFieldValues, TContext, TTransformedValues>,
119 'formState'
120 >;
121} {
122 let _options = {
123 ...defaultOptions,
124 ...props,
125 };
126 let _formState: FormState<TFieldValues> = {
127 submitCount: 0,
128 isDirty: false,
129 isReady: false,
130 isLoading: isFunction(_options.defaultValues),
131 isValidating: false,
132 isSubmitted: false,
133 isSubmitting: false,
134 isSubmitSuccessful: false,
135 isValid: false,
136 touchedFields: {},
137 dirtyFields: {},
138 validatingFields: {},
139 errors: _options.errors || {},
140 disabled: _options.disabled || false,
141 };
142 let _fields: FieldRefs = {};
143 let _defaultValues =
144 isObject(_options.defaultValues) || isObject(_options.values)
145 ? cloneObject(_options.defaultValues || _options.values) || {}
146 : {};
147 let _formValues = _options.shouldUnregister
148 ? ({} as TFieldValues)
149 : (cloneObject(_defaultValues) as TFieldValues);
150 let _state = {
151 action: false,
152 mount: false,
153 watch: false,
154 keepIsValid: false,
155 };
156 let _names: Names = {
157 mount: new Set(),
158 disabled: new Set(),
159 unMount: new Set(),
160 array: new Set(),
161 watch: new Set(),
162 registerName: new Set(),
163 };
164 let delayErrorCallback: DelayCallback | null;

Callers 3

useFormFunction · 0.90
useForm.test.tsxFile · 0.85

Calls 1

cloneObjectFunction · 0.85

Tested by

no test coverage detected