react-hook-form 7.43.2 → 7.43.3

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.
@@ -328,7 +328,7 @@ function useWatch(props) {
328
328
  _name.current = name;
329
329
  useSubscribe({
330
330
  disabled,
331
- subject: control._subjects.watch,
331
+ subject: control._subjects.values,
332
332
  next: (formState) => {
333
333
  if (shouldSubscribeByName(_name.current, formState.name, exact)) {
334
334
  updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
@@ -1083,7 +1083,10 @@ function useFieldArray(props) {
1083
1083
  };
1084
1084
  React.useEffect(() => {
1085
1085
  control._stateFlags.action = false;
1086
- isWatched(name, control._names) && control._subjects.state.next({});
1086
+ isWatched(name, control._names) &&
1087
+ control._subjects.state.next({
1088
+ ...control._formState,
1089
+ });
1087
1090
  if (_actioned.current &&
1088
1091
  (!getValidationModes(control._options.mode).isOnSubmit ||
1089
1092
  control._formState.isSubmitted)) {
@@ -1111,7 +1114,7 @@ function useFieldArray(props) {
1111
1114
  }
1112
1115
  }
1113
1116
  }
1114
- control._subjects.watch.next({
1117
+ control._subjects.values.next({
1115
1118
  name,
1116
1119
  values: control._formValues,
1117
1120
  });
@@ -1255,9 +1258,7 @@ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues
1255
1258
  }
1256
1259
  }
1257
1260
  else {
1258
- deepEqual(data[key], formValues[key])
1259
- ? delete dirtyFieldsFromValues[key]
1260
- : (dirtyFieldsFromValues[key] = true);
1261
+ dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
1261
1262
  }
1262
1263
  }
1263
1264
  }
@@ -1432,7 +1433,7 @@ function createFormControl(props = {}, flushRootRender) {
1432
1433
  errors: false,
1433
1434
  };
1434
1435
  const _subjects = {
1435
- watch: createSubject(),
1436
+ values: createSubject(),
1436
1437
  array: createSubject(),
1437
1438
  state: createSubject(),
1438
1439
  };
@@ -1684,8 +1685,9 @@ function createFormControl(props = {}, flushRootRender) {
1684
1685
  else {
1685
1686
  fieldReference.ref.value = fieldValue;
1686
1687
  if (!fieldReference.ref.type) {
1687
- _subjects.watch.next({
1688
+ _subjects.values.next({
1688
1689
  name,
1690
+ values: { ..._formValues },
1689
1691
  });
1690
1692
  }
1691
1693
  }
@@ -1716,7 +1718,7 @@ function createFormControl(props = {}, flushRootRender) {
1716
1718
  if (isFieldArray) {
1717
1719
  _subjects.array.next({
1718
1720
  name,
1719
- values: _formValues,
1721
+ values: { ..._formValues },
1720
1722
  });
1721
1723
  if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
1722
1724
  options.shouldDirty) {
@@ -1732,9 +1734,10 @@ function createFormControl(props = {}, flushRootRender) {
1732
1734
  ? setValues(name, cloneValue, options)
1733
1735
  : setFieldValue(name, cloneValue, options);
1734
1736
  }
1735
- isWatched(name, _names) && _subjects.state.next({});
1736
- _subjects.watch.next({
1737
+ isWatched(name, _names) && _subjects.state.next({ ..._formState });
1738
+ _subjects.values.next({
1737
1739
  name,
1740
+ values: { ..._formValues },
1738
1741
  });
1739
1742
  !_stateFlags.mount && flushRootRender();
1740
1743
  };
@@ -1765,16 +1768,17 @@ function createFormControl(props = {}, flushRootRender) {
1765
1768
  const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
1766
1769
  const shouldRender = !isEmptyObject(fieldState) || watched;
1767
1770
  !isBlurEvent &&
1768
- _subjects.watch.next({
1771
+ _subjects.values.next({
1769
1772
  name,
1770
1773
  type: event.type,
1774
+ values: { ..._formValues },
1771
1775
  });
1772
1776
  if (shouldSkipValidation) {
1773
1777
  _proxyFormState.isValid && _updateValid();
1774
1778
  return (shouldRender &&
1775
1779
  _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1776
1780
  }
1777
- !isBlurEvent && watched && _subjects.state.next({});
1781
+ !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1778
1782
  _updateIsValidating(true);
1779
1783
  if (_options.resolver) {
1780
1784
  const { errors } = await _executeSchema([name]);
@@ -1872,7 +1876,7 @@ function createFormControl(props = {}, flushRootRender) {
1872
1876
  options && options.shouldFocus && ref && ref.focus && ref.focus();
1873
1877
  };
1874
1878
  const watch = (name, defaultValue) => isFunction(name)
1875
- ? _subjects.watch.subscribe({
1879
+ ? _subjects.values.subscribe({
1876
1880
  next: (payload) => name(_getWatch(undefined, defaultValue), payload),
1877
1881
  })
1878
1882
  : _getWatch(name, defaultValue, true);
@@ -1893,7 +1897,9 @@ function createFormControl(props = {}, flushRootRender) {
1893
1897
  unset(_defaultValues, fieldName);
1894
1898
  }
1895
1899
  }
1896
- _subjects.watch.next({});
1900
+ _subjects.values.next({
1901
+ values: { ..._formValues },
1902
+ });
1897
1903
  _subjects.state.next({
1898
1904
  ..._formState,
1899
1905
  ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
@@ -2090,7 +2096,7 @@ function createFormControl(props = {}, flushRootRender) {
2090
2096
  _subjects.array.next({
2091
2097
  values,
2092
2098
  });
2093
- _subjects.watch.next({
2099
+ _subjects.values.next({
2094
2100
  values,
2095
2101
  });
2096
2102
  }
@@ -2292,6 +2298,11 @@ function useForm(props = {}) {
2292
2298
  }
2293
2299
  },
2294
2300
  });
2301
+ React.useEffect(() => {
2302
+ if (props.values && !deepEqual(props.values, control._defaultValues)) {
2303
+ control._reset(props.values, control._options.resetOptions);
2304
+ }
2305
+ }, [props.values, control]);
2295
2306
  React.useEffect(() => {
2296
2307
  if (!control._stateFlags.mount) {
2297
2308
  control._updateValid();
@@ -2299,15 +2310,10 @@ function useForm(props = {}) {
2299
2310
  }
2300
2311
  if (control._stateFlags.watch) {
2301
2312
  control._stateFlags.watch = false;
2302
- control._subjects.state.next({});
2313
+ control._subjects.state.next({ ...control._formState });
2303
2314
  }
2304
2315
  control._removeUnmounted();
2305
2316
  });
2306
- React.useEffect(() => {
2307
- if (props.values && !deepEqual(props.values, control._defaultValues)) {
2308
- control._reset(props.values, control._options.resetOptions);
2309
- }
2310
- }, [props.values, control]);
2311
2317
  _formControl.current.formState = getProxyFormState(formState, control);
2312
2318
  return _formControl.current;
2313
2319
  }