MCPcopy
hub / github.com/react-hook-form/react-hook-form / createFormControl

Function createFormControl

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

Source from the content-addressed store, hash-verified

124};
125
126export function createFormControl<
127 TFieldValues extends FieldValues = FieldValues,
128 TContext = any,
129 TTransformedValues = TFieldValues,
130>(
131 props: UseFormProps<TFieldValues, TContext, TTransformedValues> = {},
132): Omit<
133 UseFormReturn<TFieldValues, TContext, TTransformedValues>,
134 'formState'
135> & {
136 formControl: Omit<
137 UseFormReturn<TFieldValues, TContext, TTransformedValues>,
138 'formState'
139 >;
140} {
141 let _options = {
142 ...defaultOptions,
143 ...props,
144 };
145 let _formState: FormState<TFieldValues> & {
146 values?: TFieldValues;
147 name?: string;
148 type?: EventType;
149 } = {
150 ...cloneObject(DEFAULT_FORM_STATE),
151 isLoading: isFunction(_options.defaultValues),
152 errors: _options.errors || {},
153 disabled: _options.disabled || false,
154 };
155 let _fields: FieldRefs = {};
156 let _defaultValues =
157 isObject(_options.defaultValues) || isObject(_options.values)
158 ? cloneObject(_options.defaultValues || _options.values) || {}
159 : {};
160 let _formValues = _options.shouldUnregister
161 ? ({} as TFieldValues)
162 : (cloneObject(_defaultValues) as TFieldValues);
163 let _state = {
164 action: false,
165 mount: false,
166 watch: false,
167 keepIsValid: false,
168 };
169 let _names: Names = {
170 mount: new Set(),
171 disabled: new Set(),
172 unMount: new Set(),
173 array: new Set(),
174 watch: new Set(),
175 registerName: new Set(),
176 };
177 let delayErrorCallback: DelayCallback | null;
178 let timer = 0;
179 let _valuesSubscriberCount = 0;
180 let _validationModeBeforeSubmit = getValidationModes(_options.mode);
181 let _validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
182 const defaultProxyFormState: ReadFormState = {
183 isDirty: false,

Callers 4

useFormFunction · 0.90
bench.tsFile · 0.90
useForm.test.tsxFile · 0.85

Calls 1

cloneObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…