react-hook-form 7.43.3 → 7.43.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.
@@ -393,7 +393,7 @@ function useController(props) {
393
393
  return () => {
394
394
  const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
395
395
  (isArrayField
396
- ? _shouldUnregisterField && !control._stateFlags.action
396
+ ? _shouldUnregisterField && !control._state.action
397
397
  : _shouldUnregisterField)
398
398
  ? control.unregister(name)
399
399
  : updateMounted(name, false);
@@ -1082,7 +1082,7 @@ function useFieldArray(props) {
1082
1082
  control._updateFieldArray(name, [...updatedFieldArrayValues], (data) => data, {}, true, false);
1083
1083
  };
1084
1084
  React.useEffect(() => {
1085
- control._stateFlags.action = false;
1085
+ control._state.action = false;
1086
1086
  isWatched(name, control._names) &&
1087
1087
  control._subjects.state.next({
1088
1088
  ...control._formState,
@@ -1116,7 +1116,7 @@ function useFieldArray(props) {
1116
1116
  }
1117
1117
  control._subjects.values.next({
1118
1118
  name,
1119
- values: control._formValues,
1119
+ values: { ...control._formValues },
1120
1120
  });
1121
1121
  control._names.focus &&
1122
1122
  focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus || ''));
@@ -1149,11 +1149,8 @@ function useFieldArray(props) {
1149
1149
  function createSubject() {
1150
1150
  let _observers = [];
1151
1151
  const next = (value) => {
1152
- let x = 0;
1153
- const l = _observers.length;
1154
- while (x < l) {
1155
- _observers[x].next(value);
1156
- ++x;
1152
+ for (const observer of _observers) {
1153
+ observer.next && observer.next(value);
1157
1154
  }
1158
1155
  };
1159
1156
  const subscribe = (observer) => {
@@ -1410,7 +1407,7 @@ function createFormControl(props = {}, flushRootRender) {
1410
1407
  let _formValues = _options.shouldUnregister
1411
1408
  ? {}
1412
1409
  : cloneObject(_defaultValues);
1413
- let _stateFlags = {
1410
+ let _state = {
1414
1411
  action: false,
1415
1412
  mount: false,
1416
1413
  watch: false,
@@ -1423,7 +1420,6 @@ function createFormControl(props = {}, flushRootRender) {
1423
1420
  };
1424
1421
  let delayErrorCallback;
1425
1422
  let timer = 0;
1426
- const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
1427
1423
  const _proxyFormState = {
1428
1424
  isDirty: false,
1429
1425
  dirtyFields: false,
@@ -1437,6 +1433,7 @@ function createFormControl(props = {}, flushRootRender) {
1437
1433
  array: createSubject(),
1438
1434
  state: createSubject(),
1439
1435
  };
1436
+ const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
1440
1437
  const validationModeBeforeSubmit = getValidationModes(_options.mode);
1441
1438
  const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1442
1439
  const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
@@ -1462,7 +1459,7 @@ function createFormControl(props = {}, flushRootRender) {
1462
1459
  });
1463
1460
  const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1464
1461
  if (args && method) {
1465
- _stateFlags.action = true;
1462
+ _state.action = true;
1466
1463
  if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1467
1464
  const fieldValues = method(get(_fields, name), args.argA, args.argB);
1468
1465
  shouldSetValues && set(_fields, name, fieldValues);
@@ -1509,7 +1506,7 @@ function createFormControl(props = {}, flushRootRender) {
1509
1506
  shouldSkipSetValueAs
1510
1507
  ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
1511
1508
  : setFieldValue(name, defaultValue);
1512
- _stateFlags.mount && _updateValid();
1509
+ _state.mount && _updateValid();
1513
1510
  }
1514
1511
  };
1515
1512
  const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
@@ -1582,7 +1579,7 @@ function createFormControl(props = {}, flushRootRender) {
1582
1579
  }
1583
1580
  _updateIsValidating(false);
1584
1581
  };
1585
- const _executeSchema = async (name) => await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1582
+ const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1586
1583
  const executeSchemaAndUpdateState = async (names) => {
1587
1584
  const { errors } = await _executeSchema();
1588
1585
  if (names) {
@@ -1641,7 +1638,7 @@ function createFormControl(props = {}, flushRootRender) {
1641
1638
  const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
1642
1639
  !deepEqual(getValues(), _defaultValues));
1643
1640
  const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1644
- ...(_stateFlags.mount
1641
+ ...(_state.mount
1645
1642
  ? _formValues
1646
1643
  : isUndefined(defaultValue)
1647
1644
  ? _defaultValues
@@ -1649,7 +1646,7 @@ function createFormControl(props = {}, flushRootRender) {
1649
1646
  ? { [names]: defaultValue }
1650
1647
  : defaultValue),
1651
1648
  }, isGlobal, defaultValue);
1652
- const _getFieldArray = (name) => compact(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
1649
+ const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
1653
1650
  const setFieldValue = (name, value, options = {}) => {
1654
1651
  const field = get(_fields, name);
1655
1652
  let fieldValue = value;
@@ -1739,7 +1736,7 @@ function createFormControl(props = {}, flushRootRender) {
1739
1736
  name,
1740
1737
  values: { ..._formValues },
1741
1738
  });
1742
- !_stateFlags.mount && flushRootRender();
1739
+ !_state.mount && flushRootRender();
1743
1740
  };
1744
1741
  const onChange = async (event) => {
1745
1742
  const target = event.target;
@@ -1841,7 +1838,7 @@ function createFormControl(props = {}, flushRootRender) {
1841
1838
  const getValues = (fieldNames) => {
1842
1839
  const values = {
1843
1840
  ..._defaultValues,
1844
- ...(_stateFlags.mount ? _formValues : {}),
1841
+ ...(_state.mount ? _formValues : {}),
1845
1842
  };
1846
1843
  return isUndefined(fieldNames)
1847
1844
  ? values
@@ -1979,7 +1976,7 @@ function createFormControl(props = {}, flushRootRender) {
1979
1976
  field._f.mount = false;
1980
1977
  }
1981
1978
  (_options.shouldUnregister || options.shouldUnregister) &&
1982
- !(isNameInFieldArray(_names.array, name) && _stateFlags.action) &&
1979
+ !(isNameInFieldArray(_names.array, name) && _state.action) &&
1983
1980
  _names.unMount.add(name);
1984
1981
  }
1985
1982
  },
@@ -2094,10 +2091,10 @@ function createFormControl(props = {}, flushRootRender) {
2094
2091
  : {}
2095
2092
  : cloneUpdatedValues;
2096
2093
  _subjects.array.next({
2097
- values,
2094
+ values: { ...values },
2098
2095
  });
2099
2096
  _subjects.values.next({
2100
- values,
2097
+ values: { ...values },
2101
2098
  });
2102
2099
  }
2103
2100
  _names = {
@@ -2108,10 +2105,9 @@ function createFormControl(props = {}, flushRootRender) {
2108
2105
  watchAll: false,
2109
2106
  focus: '',
2110
2107
  };
2111
- !_stateFlags.mount && flushRootRender();
2112
- _stateFlags.mount =
2113
- !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
2114
- _stateFlags.watch = !!props.shouldUnregister;
2108
+ !_state.mount && flushRootRender();
2109
+ _state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
2110
+ _state.watch = !!props.shouldUnregister;
2115
2111
  _subjects.state.next({
2116
2112
  submitCount: keepStateOptions.keepSubmitCount
2117
2113
  ? _formState.submitCount
@@ -2188,11 +2184,11 @@ function createFormControl(props = {}, flushRootRender) {
2188
2184
  get _formValues() {
2189
2185
  return _formValues;
2190
2186
  },
2191
- get _stateFlags() {
2192
- return _stateFlags;
2187
+ get _state() {
2188
+ return _state;
2193
2189
  },
2194
- set _stateFlags(value) {
2195
- _stateFlags = value;
2190
+ set _state(value) {
2191
+ _state = value;
2196
2192
  },
2197
2193
  get _defaultValues() {
2198
2194
  return _defaultValues;
@@ -2304,12 +2300,12 @@ function useForm(props = {}) {
2304
2300
  }
2305
2301
  }, [props.values, control]);
2306
2302
  React.useEffect(() => {
2307
- if (!control._stateFlags.mount) {
2303
+ if (!control._state.mount) {
2308
2304
  control._updateValid();
2309
- control._stateFlags.mount = true;
2305
+ control._state.mount = true;
2310
2306
  }
2311
- if (control._stateFlags.watch) {
2312
- control._stateFlags.watch = false;
2307
+ if (control._state.watch) {
2308
+ control._state.watch = false;
2313
2309
  control._subjects.state.next({ ...control._formState });
2314
2310
  }
2315
2311
  control._removeUnmounted();