react-hook-form 7.27.1 → 7.28.0-next.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.
@@ -733,13 +733,14 @@ function useFieldArray(props) {
733
733
  }, false);
734
734
  };
735
735
  const update = (index, value) => {
736
- const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, value);
736
+ const updateValue = cloneObject(value);
737
+ const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, updateValue);
737
738
  ids.current = [...updatedFieldArrayValues].map((item, i) => !item || i === index ? generateId() : ids.current[i]);
738
739
  updateValues(updatedFieldArrayValues);
739
740
  setFields([...updatedFieldArrayValues]);
740
741
  control._updateFieldArray(name, updatedFieldArrayValues, updateAt, {
741
742
  argA: index,
742
- argB: value,
743
+ argB: updateValue,
743
744
  }, true, false);
744
745
  };
745
746
  const replace = (value) => {
@@ -1344,21 +1345,22 @@ function createFormControl(props = {}) {
1344
1345
  }
1345
1346
  return isValid;
1346
1347
  };
1347
- const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndErrors = true) => {
1348
+ const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1348
1349
  if (args && method) {
1349
1350
  _stateFlags.action = true;
1350
- if (shouldUpdateFieldsAndErrors && Array.isArray(get(_fields, name))) {
1351
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1351
1352
  const fieldValues = method(get(_fields, name), args.argA, args.argB);
1352
1353
  shouldSetValues && set(_fields, name, fieldValues);
1353
1354
  }
1354
1355
  if (_proxyFormState.errors &&
1355
- shouldUpdateFieldsAndErrors &&
1356
+ shouldUpdateFieldsAndState &&
1356
1357
  Array.isArray(get(_formState.errors, name))) {
1357
1358
  const errors = method(get(_formState.errors, name), args.argA, args.argB);
1358
1359
  shouldSetValues && set(_formState.errors, name, errors);
1359
1360
  unsetEmptyArray(_formState.errors, name);
1360
1361
  }
1361
1362
  if (_proxyFormState.touchedFields &&
1363
+ shouldUpdateFieldsAndState &&
1362
1364
  Array.isArray(get(_formState.touchedFields, name))) {
1363
1365
  const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
1364
1366
  shouldSetValues && set(_formState.touchedFields, name, touchedFields);
@@ -1667,7 +1669,8 @@ function createFormControl(props = {}) {
1667
1669
  error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1668
1670
  isValid = await _updateValid(true);
1669
1671
  }
1670
- field._f.deps && trigger(field._f.deps);
1672
+ field._f.deps &&
1673
+ trigger(field._f.deps);
1671
1674
  shouldRenderByError(false, name, isValid, error, fieldState);
1672
1675
  }
1673
1676
  };