react-hook-form 7.28.0 → 7.30.0

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.
@@ -18,11 +18,11 @@ var getEventValue = (event) => isObject(event) && event.target
18
18
  : event.target.value
19
19
  : event;
20
20
 
21
- var getNodeParentName = (name) => name.substring(0, name.search(/.\d/)) || name;
21
+ var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
22
22
 
23
- var isNameInFieldArray = (names, name) => [...names].some((current) => getNodeParentName(name) === current);
23
+ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
24
24
 
25
- var compact = (value) => value.filter(Boolean);
25
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
26
26
 
27
27
  var isUndefined = (val) => val === undefined;
28
28
 
@@ -60,12 +60,6 @@ const INPUT_VALIDATION_RULES = {
60
60
  validate: 'validate',
61
61
  };
62
62
 
63
- var omit = (source, key) => {
64
- const copy = Object.assign({}, source);
65
- delete copy[key];
66
- return copy;
67
- };
68
-
69
63
  const HookFormContext = React.createContext(null);
70
64
  /**
71
65
  * 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}.
@@ -128,7 +122,10 @@ const useFormContext = () => React.useContext(HookFormContext);
128
122
  * }
129
123
  * ```
130
124
  */
131
- const FormProvider = (props) => (React.createElement(HookFormContext.Provider, { value: omit(props, 'children') }, props.children));
125
+ const FormProvider = (props) => {
126
+ const { children, ...data } = props;
127
+ return (React.createElement(HookFormContext.Provider, { value: data }, props.children));
128
+ };
132
129
 
133
130
  var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot = true) => {
134
131
  const result = {};
@@ -150,7 +147,7 @@ var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot
150
147
  var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
151
148
 
152
149
  var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
153
- const formState = omit(formStateData, 'name');
150
+ const { name, ...formState } = formStateData;
154
151
  return (isEmptyObject(formState) ||
155
152
  Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
156
153
  Object.keys(formState).find((key) => _proxyFormState[key] ===
@@ -233,14 +230,20 @@ function useFormState(props) {
233
230
  const callback = React.useCallback((value) => _mounted.current &&
234
231
  shouldSubscribeByName(_name.current, value.name, exact) &&
235
232
  shouldRenderFormState(value, _localProxyFormState.current) &&
236
- updateFormState(Object.assign(Object.assign({}, control._formState), value)), [control, exact]);
233
+ updateFormState({
234
+ ...control._formState,
235
+ ...value,
236
+ }), [control, exact]);
237
237
  useSubscribe({
238
238
  disabled,
239
239
  callback,
240
240
  subject: control._subjects.state,
241
241
  });
242
- React.useEffect(() => () => {
243
- _mounted.current = false;
242
+ React.useEffect(() => {
243
+ _mounted.current = true;
244
+ return () => {
245
+ _mounted.current = false;
246
+ };
244
247
  }, []);
245
248
  return getProxyFormState(formState, control._proxyFormState, _localProxyFormState.current, false);
246
249
  }
@@ -298,11 +301,12 @@ function useWatch(props) {
298
301
  const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
299
302
  updateValue(isUndefined(_name.current) ||
300
303
  (isObject(fieldValues) && !objectHasFunction(fieldValues))
301
- ? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
302
- ? [...fieldValues]
303
- : isUndefined(fieldValues)
304
- ? defaultValue
305
- : fieldValues);
304
+ ? { ...fieldValues }
305
+ : Array.isArray(fieldValues)
306
+ ? [...fieldValues]
307
+ : isUndefined(fieldValues)
308
+ ? defaultValue
309
+ : fieldValues);
306
310
  }
307
311
  }, [control, exact, defaultValue]);
308
312
  useSubscribe({
@@ -357,7 +361,10 @@ function useController(props) {
357
361
  control,
358
362
  name,
359
363
  });
360
- const _registerProps = React.useRef(control.register(name, Object.assign(Object.assign({}, props.rules), { value })));
364
+ const _registerProps = React.useRef(control.register(name, {
365
+ ...props.rules,
366
+ value,
367
+ }));
361
368
  React.useEffect(() => {
362
369
  const updateMounted = (name, value) => {
363
370
  const field = get(control._fields, name);
@@ -458,7 +465,14 @@ function useController(props) {
458
465
  const Controller = (props) => props.render(useController(props));
459
466
 
460
467
  var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
461
- ? Object.assign(Object.assign({}, errors[name]), { types: Object.assign(Object.assign({}, (errors[name] && errors[name].types ? errors[name].types : {})), { [type]: message || true }) }) : {};
468
+ ? {
469
+ ...errors[name],
470
+ types: {
471
+ ...(errors[name] && errors[name].types ? errors[name].types : {}),
472
+ [type]: message || true,
473
+ },
474
+ }
475
+ : {};
462
476
 
463
477
  var isKey = (value) => /^\w*$/.test(value);
464
478
 
@@ -491,8 +505,7 @@ const focusFieldBy = (fields, callback, fieldsNames) => {
491
505
  for (const key of fieldsNames || Object.keys(fields)) {
492
506
  const field = get(fields, key);
493
507
  if (field) {
494
- const _f = field._f;
495
- const current = omit(field, '_f');
508
+ const { _f, ...currentField } = field;
496
509
  if (_f && callback(_f.name)) {
497
510
  if (_f.ref.focus && isUndefined(_f.ref.focus())) {
498
511
  break;
@@ -502,8 +515,8 @@ const focusFieldBy = (fields, callback, fieldsNames) => {
502
515
  break;
503
516
  }
504
517
  }
505
- else if (isObject(current)) {
506
- focusFieldBy(current, callback);
518
+ else if (isObject(currentField)) {
519
+ focusFieldBy(currentField, callback);
507
520
  }
508
521
  }
509
522
  }
@@ -789,7 +802,10 @@ function useFieldArray(props) {
789
802
  insert: React.useCallback(insert$1, [updateValues, name, control]),
790
803
  update: React.useCallback(update, [updateValues, name, control]),
791
804
  replace: React.useCallback(replace, [updateValues, name, control]),
792
- fields: React.useMemo(() => fields.map((field, index) => (Object.assign(Object.assign({}, field), { [keyName]: ids.current[index] || generateId() }))), [fields, keyName]),
805
+ fields: React.useMemo(() => fields.map((field, index) => ({
806
+ ...field,
807
+ [keyName]: ids.current[index] || generateId(),
808
+ })), [fields, keyName]),
793
809
  };
794
810
  }
795
811
 
@@ -945,7 +961,7 @@ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues
945
961
  isPrimitive(dirtyFieldsFromValues[key])) {
946
962
  dirtyFieldsFromValues[key] = Array.isArray(data[key])
947
963
  ? markFieldsDirty(data[key], [])
948
- : Object.assign({}, markFieldsDirty(data[key]));
964
+ : { ...markFieldsDirty(data[key]) };
949
965
  }
950
966
  else {
951
967
  getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
@@ -1155,8 +1171,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1155
1171
  const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
1156
1172
  const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
1157
1173
  const message = exceedMax ? maxLengthMessage : minLengthMessage;
1158
- error[name] = Object.assign({ type: exceedMax ? maxType : minType, message,
1159
- ref }, appendErrorsCurry(exceedMax ? maxType : minType, message));
1174
+ error[name] = {
1175
+ type: exceedMax ? maxType : minType,
1176
+ message,
1177
+ ref,
1178
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message),
1179
+ };
1160
1180
  };
1161
1181
  if (required &&
1162
1182
  ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
@@ -1167,7 +1187,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1167
1187
  ? { value: !!required, message: required }
1168
1188
  : getValueAndMessage(required);
1169
1189
  if (value) {
1170
- error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.required, message, ref: inputRef }, appendErrorsCurry(INPUT_VALIDATION_RULES.required, message));
1190
+ error[name] = {
1191
+ type: INPUT_VALIDATION_RULES.required,
1192
+ message,
1193
+ ref: inputRef,
1194
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
1195
+ };
1171
1196
  if (!validateAllFieldCriteria) {
1172
1197
  setCustomValidity(message);
1173
1198
  return error;
@@ -1223,8 +1248,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1223
1248
  if (pattern && !isEmpty && isString(inputValue)) {
1224
1249
  const { value: patternValue, message } = getValueAndMessage(pattern);
1225
1250
  if (isRegex(patternValue) && !inputValue.match(patternValue)) {
1226
- error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.pattern, message,
1227
- ref }, appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message));
1251
+ error[name] = {
1252
+ type: INPUT_VALIDATION_RULES.pattern,
1253
+ message,
1254
+ ref,
1255
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
1256
+ };
1228
1257
  if (!validateAllFieldCriteria) {
1229
1258
  setCustomValidity(message);
1230
1259
  return error;
@@ -1236,7 +1265,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1236
1265
  const result = await validate(inputValue);
1237
1266
  const validateError = getValidateError(result, inputRef);
1238
1267
  if (validateError) {
1239
- error[name] = Object.assign(Object.assign({}, validateError), appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message));
1268
+ error[name] = {
1269
+ ...validateError,
1270
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
1271
+ };
1240
1272
  if (!validateAllFieldCriteria) {
1241
1273
  setCustomValidity(validateError.message);
1242
1274
  return error;
@@ -1251,7 +1283,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1251
1283
  }
1252
1284
  const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
1253
1285
  if (validateError) {
1254
- validationResult = Object.assign(Object.assign({}, validateError), appendErrorsCurry(key, validateError.message));
1286
+ validationResult = {
1287
+ ...validateError,
1288
+ ...appendErrorsCurry(key, validateError.message),
1289
+ };
1255
1290
  setCustomValidity(validateError.message);
1256
1291
  if (validateAllFieldCriteria) {
1257
1292
  error[name] = validationResult;
@@ -1259,7 +1294,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1259
1294
  }
1260
1295
  }
1261
1296
  if (!isEmptyObject(validationResult)) {
1262
- error[name] = Object.assign({ ref: inputRef }, validationResult);
1297
+ error[name] = {
1298
+ ref: inputRef,
1299
+ ...validationResult,
1300
+ };
1263
1301
  if (!validateAllFieldCriteria) {
1264
1302
  return error;
1265
1303
  }
@@ -1276,7 +1314,10 @@ const defaultOptions = {
1276
1314
  shouldFocusError: true,
1277
1315
  };
1278
1316
  function createFormControl(props = {}) {
1279
- let _options = Object.assign(Object.assign({}, defaultOptions), props);
1317
+ let _options = {
1318
+ ...defaultOptions,
1319
+ ...props,
1320
+ };
1280
1321
  let _formState = {
1281
1322
  isDirty: false,
1282
1323
  isValidating: false,
@@ -1290,7 +1331,7 @@ function createFormControl(props = {}) {
1290
1331
  errors: {},
1291
1332
  };
1292
1333
  let _fields = {};
1293
- let _defaultValues = _options.defaultValues || {};
1334
+ let _defaultValues = cloneObject(_options.defaultValues) || {};
1294
1335
  let _formValues = _options.shouldUnregister
1295
1336
  ? {}
1296
1337
  : cloneObject(_defaultValues);
@@ -1444,8 +1485,16 @@ function createFormControl(props = {}) {
1444
1485
  !isEmptyObject(fieldState) ||
1445
1486
  shouldUpdateValid) &&
1446
1487
  !shouldSkipRender) {
1447
- const updatedFormState = Object.assign(Object.assign(Object.assign({}, fieldState), (shouldUpdateValid ? { isValid } : {})), { errors: _formState.errors, name });
1448
- _formState = Object.assign(Object.assign({}, _formState), updatedFormState);
1488
+ const updatedFormState = {
1489
+ ...fieldState,
1490
+ ...(shouldUpdateValid ? { isValid } : {}),
1491
+ errors: _formState.errors,
1492
+ name,
1493
+ };
1494
+ _formState = {
1495
+ ..._formState,
1496
+ ...updatedFormState,
1497
+ };
1449
1498
  _subjects.state.next(updatedFormState);
1450
1499
  }
1451
1500
  validateFields[name]--;
@@ -1458,7 +1507,7 @@ function createFormControl(props = {}) {
1458
1507
  }
1459
1508
  };
1460
1509
  const _executeSchema = async (name) => _options.resolver
1461
- ? await _options.resolver(Object.assign({}, _formValues), _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
1510
+ ? await _options.resolver({ ..._formValues }, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
1462
1511
  : {};
1463
1512
  const executeSchemaAndUpdateState = async (names) => {
1464
1513
  const { errors } = await _executeSchema();
@@ -1481,8 +1530,7 @@ function createFormControl(props = {}) {
1481
1530
  for (const name in fields) {
1482
1531
  const field = fields[name];
1483
1532
  if (field) {
1484
- const fieldReference = field._f;
1485
- const fieldValue = omit(field, '_f');
1533
+ const { _f: fieldReference, ...fieldValue } = field;
1486
1534
  if (fieldReference) {
1487
1535
  const fieldError = await validateField(field, get(_formValues, fieldReference.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation);
1488
1536
  if (fieldError[fieldReference.name]) {
@@ -1517,13 +1565,15 @@ function createFormControl(props = {}) {
1517
1565
  const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
1518
1566
  !deepEqual(getValues(), _defaultValues));
1519
1567
  const _getWatch = (names, defaultValue, isGlobal) => {
1520
- const fieldValues = Object.assign({}, (_stateFlags.mount
1521
- ? _formValues
1522
- : isUndefined(defaultValue)
1523
- ? _defaultValues
1524
- : isString(names)
1525
- ? { [names]: defaultValue }
1526
- : defaultValue));
1568
+ const fieldValues = {
1569
+ ...(_stateFlags.mount
1570
+ ? _formValues
1571
+ : isUndefined(defaultValue)
1572
+ ? _defaultValues
1573
+ : isString(names)
1574
+ ? { [names]: defaultValue }
1575
+ : defaultValue),
1576
+ };
1527
1577
  return generateWatchOutput(names, _names, fieldValues, isGlobal);
1528
1578
  };
1529
1579
  const _getFieldArray = (name) => compact(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
@@ -1545,9 +1595,10 @@ function createFormControl(props = {}) {
1545
1595
  else if (fieldReference.refs) {
1546
1596
  if (isCheckBoxInput(fieldReference.ref)) {
1547
1597
  fieldReference.refs.length > 1
1548
- ? fieldReference.refs.forEach((checkboxRef) => (checkboxRef.checked = Array.isArray(fieldValue)
1549
- ? !!fieldValue.find((data) => data === checkboxRef.value)
1550
- : fieldValue === checkboxRef.value))
1598
+ ? fieldReference.refs.forEach((checkboxRef) => !checkboxRef.disabled &&
1599
+ (checkboxRef.checked = Array.isArray(fieldValue)
1600
+ ? !!fieldValue.find((data) => data === checkboxRef.value)
1601
+ : fieldValue === checkboxRef.value))
1551
1602
  : fieldReference.refs[0] &&
1552
1603
  (fieldReference.refs[0].checked = !!fieldValue);
1553
1604
  }
@@ -1648,7 +1699,7 @@ function createFormControl(props = {}) {
1648
1699
  });
1649
1700
  if (shouldSkipValidation) {
1650
1701
  return (shouldRender &&
1651
- _subjects.state.next(Object.assign({ name }, (watched ? {} : fieldState))));
1702
+ _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1652
1703
  }
1653
1704
  !isBlurEvent && watched && _subjects.state.next({});
1654
1705
  validateFields[name] = validateFields[name] ? +1 : 1;
@@ -1696,17 +1747,25 @@ function createFormControl(props = {}) {
1696
1747
  else {
1697
1748
  validationResult = isValid = await executeBuildInValidation(_fields);
1698
1749
  }
1699
- _subjects.state.next(Object.assign(Object.assign(Object.assign({}, (!isString(name) ||
1700
- (_proxyFormState.isValid && isValid !== _formState.isValid)
1701
- ? {}
1702
- : { name })), (_options.resolver ? { isValid } : {})), { errors: _formState.errors, isValidating: false }));
1750
+ _subjects.state.next({
1751
+ ...(!isString(name) ||
1752
+ (_proxyFormState.isValid && isValid !== _formState.isValid)
1753
+ ? {}
1754
+ : { name }),
1755
+ ...(_options.resolver ? { isValid } : {}),
1756
+ errors: _formState.errors,
1757
+ isValidating: false,
1758
+ });
1703
1759
  options.shouldFocus &&
1704
1760
  !validationResult &&
1705
1761
  focusFieldBy(_fields, (key) => get(_formState.errors, key), name ? fieldNames : _names.mount);
1706
1762
  return validationResult;
1707
1763
  };
1708
1764
  const getValues = (fieldNames) => {
1709
- const values = Object.assign(Object.assign({}, _defaultValues), (_stateFlags.mount ? _formValues : {}));
1765
+ const values = {
1766
+ ..._defaultValues,
1767
+ ...(_stateFlags.mount ? _formValues : {}),
1768
+ };
1710
1769
  return isUndefined(fieldNames)
1711
1770
  ? values
1712
1771
  : isString(fieldNames)
@@ -1729,7 +1788,10 @@ function createFormControl(props = {}) {
1729
1788
  };
1730
1789
  const setError = (name, error, options) => {
1731
1790
  const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1732
- set(_formState.errors, name, Object.assign(Object.assign({}, error), { ref }));
1791
+ set(_formState.errors, name, {
1792
+ ...error,
1793
+ ref,
1794
+ });
1733
1795
  _subjects.state.next({
1734
1796
  name,
1735
1797
  errors: _formState.errors,
@@ -1760,14 +1822,22 @@ function createFormControl(props = {}) {
1760
1822
  }
1761
1823
  }
1762
1824
  _subjects.watch.next({});
1763
- _subjects.state.next(Object.assign(Object.assign({}, _formState), (!options.keepDirty ? {} : { isDirty: _getDirty() })));
1825
+ _subjects.state.next({
1826
+ ..._formState,
1827
+ ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
1828
+ });
1764
1829
  !options.keepIsValid && _updateValid();
1765
1830
  };
1766
1831
  const register = (name, options = {}) => {
1767
1832
  let field = get(_fields, name);
1768
1833
  const disabledIsDefined = isBoolean(options.disabled);
1769
1834
  set(_fields, name, {
1770
- _f: Object.assign(Object.assign(Object.assign({}, (field && field._f ? field._f : { ref: { name } })), { name, mount: true }), options),
1835
+ _f: {
1836
+ ...(field && field._f ? field._f : { ref: { name } }),
1837
+ name,
1838
+ mount: true,
1839
+ ...options,
1840
+ },
1771
1841
  });
1772
1842
  _names.mount.add(name);
1773
1843
  field
@@ -1776,17 +1846,22 @@ function createFormControl(props = {}) {
1776
1846
  ? undefined
1777
1847
  : get(_formValues, name, getFieldValue(field._f)))
1778
1848
  : updateValidAndValue(name, true, options.value);
1779
- return Object.assign(Object.assign(Object.assign({}, (disabledIsDefined ? { disabled: options.disabled } : {})), (_options.shouldUseNativeValidation
1780
- ? {
1781
- required: !!options.required,
1782
- min: getRuleValue(options.min),
1783
- max: getRuleValue(options.max),
1784
- minLength: getRuleValue(options.minLength),
1785
- maxLength: getRuleValue(options.maxLength),
1786
- pattern: getRuleValue(options.pattern),
1787
- }
1788
- : {})), { name,
1789
- onChange, onBlur: onChange, ref: (ref) => {
1849
+ return {
1850
+ ...(disabledIsDefined ? { disabled: options.disabled } : {}),
1851
+ ...(_options.shouldUseNativeValidation
1852
+ ? {
1853
+ required: !!options.required,
1854
+ min: getRuleValue(options.min),
1855
+ max: getRuleValue(options.max),
1856
+ minLength: getRuleValue(options.minLength),
1857
+ maxLength: getRuleValue(options.maxLength),
1858
+ pattern: getRuleValue(options.pattern),
1859
+ }
1860
+ : {}),
1861
+ name,
1862
+ onChange,
1863
+ onBlur: onChange,
1864
+ ref: (ref) => {
1790
1865
  if (ref) {
1791
1866
  register(name, options);
1792
1867
  field = get(_fields, name);
@@ -1803,12 +1878,21 @@ function createFormControl(props = {}) {
1803
1878
  return;
1804
1879
  }
1805
1880
  set(_fields, name, {
1806
- _f: Object.assign(Object.assign({}, field._f), (radioOrCheckbox
1807
- ? {
1808
- refs: [...refs.filter(live), fieldRef],
1809
- ref: { type: fieldRef.type, name },
1810
- }
1811
- : { ref: fieldRef })),
1881
+ _f: {
1882
+ ...field._f,
1883
+ ...(radioOrCheckbox
1884
+ ? {
1885
+ refs: [
1886
+ ...refs.filter(live),
1887
+ fieldRef,
1888
+ ...(!!Array.isArray(get(_defaultValues, name))
1889
+ ? [{}]
1890
+ : []),
1891
+ ],
1892
+ ref: { type: fieldRef.type, name },
1893
+ }
1894
+ : { ref: fieldRef }),
1895
+ },
1812
1896
  });
1813
1897
  updateValidAndValue(name, false, undefined, fieldRef);
1814
1898
  }
@@ -1821,7 +1905,8 @@ function createFormControl(props = {}) {
1821
1905
  !(isNameInFieldArray(_names.array, name) && _stateFlags.action) &&
1822
1906
  _names.unMount.add(name);
1823
1907
  }
1824
- } });
1908
+ },
1909
+ };
1825
1910
  };
1826
1911
  const handleSubmit = (onValid, onInvalid) => async (e) => {
1827
1912
  if (e) {
@@ -1852,7 +1937,7 @@ function createFormControl(props = {}) {
1852
1937
  }
1853
1938
  else {
1854
1939
  if (onInvalid) {
1855
- await onInvalid(Object.assign({}, _formState.errors), e);
1940
+ await onInvalid({ ..._formState.errors }, e);
1856
1941
  }
1857
1942
  _options.shouldFocusError &&
1858
1943
  focusFieldBy(_fields, (key) => get(_formState.errors, key), _names.mount);
@@ -1895,7 +1980,7 @@ function createFormControl(props = {}) {
1895
1980
  unset(_formState.errors, name);
1896
1981
  _proxyFormState.isValid && _updateValid();
1897
1982
  }
1898
- _subjects.state.next(Object.assign({}, _formState));
1983
+ _subjects.state.next({ ..._formState });
1899
1984
  }
1900
1985
  };
1901
1986
  const reset = (formValues, keepStateOptions = {}) => {
@@ -1963,7 +2048,10 @@ function createFormControl(props = {}) {
1963
2048
  dirtyFields: keepStateOptions.keepDirty
1964
2049
  ? _formState.dirtyFields
1965
2050
  : (keepStateOptions.keepDefaultValues && formValues
1966
- ? Object.entries(formValues).reduce((previous, [key, value]) => (Object.assign(Object.assign({}, previous), { [key]: value !== get(_defaultValues, key) })), {})
2051
+ ? Object.entries(formValues).reduce((previous, [key, value]) => ({
2052
+ ...previous,
2053
+ [key]: value !== get(_defaultValues, key),
2054
+ }), {})
1967
2055
  : {}),
1968
2056
  touchedFields: keepStateOptions.keepTouched
1969
2057
  ? _formState.touchedFields
@@ -2025,7 +2113,10 @@ function createFormControl(props = {}) {
2025
2113
  return _options;
2026
2114
  },
2027
2115
  set _options(value) {
2028
- _options = Object.assign(Object.assign({}, _options), value);
2116
+ _options = {
2117
+ ..._options,
2118
+ ...value,
2119
+ };
2029
2120
  },
2030
2121
  },
2031
2122
  trigger,
@@ -2091,13 +2182,19 @@ function useForm(props = {}) {
2091
2182
  _formControl.current.control._options = props;
2092
2183
  }
2093
2184
  else {
2094
- _formControl.current = Object.assign(Object.assign({}, createFormControl(props)), { formState });
2185
+ _formControl.current = {
2186
+ ...createFormControl(props),
2187
+ formState,
2188
+ };
2095
2189
  }
2096
2190
  const control = _formControl.current.control;
2097
2191
  const callback = React.useCallback((value) => {
2098
2192
  if (shouldRenderFormState(value, control._proxyFormState, true)) {
2099
- control._formState = Object.assign(Object.assign({}, control._formState), value);
2100
- updateFormState(Object.assign({}, control._formState));
2193
+ control._formState = {
2194
+ ...control._formState,
2195
+ ...value,
2196
+ };
2197
+ updateFormState({ ...control._formState });
2101
2198
  }
2102
2199
  }, [control]);
2103
2200
  useSubscribe({