react-hook-form 7.59.0 → 7.60.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.
@@ -39,9 +39,6 @@ function cloneObject(data) {
39
39
  if (data instanceof Date) {
40
40
  copy = new Date(data);
41
41
  }
42
- else if (data instanceof Set) {
43
- copy = new Set(data);
44
- }
45
42
  else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
46
43
  (isArray || isObject(data))) {
47
44
  copy = isArray ? [] : {};
@@ -290,7 +287,8 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
290
287
  return get(formValues, names, defaultValue);
291
288
  }
292
289
  if (Array.isArray(names)) {
293
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
290
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
291
+ get(formValues, fieldName)));
294
292
  }
295
293
  isGlobal && (_names.watchAll = true);
296
294
  return formValues;
@@ -1280,7 +1278,7 @@ function createFormControl(props = {}) {
1280
1278
  errors: _options.errors || {},
1281
1279
  disabled: _options.disabled || false,
1282
1280
  };
1283
- const _fields = {};
1281
+ let _fields = {};
1284
1282
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1285
1283
  ? cloneObject(_options.defaultValues || _options.values) || {}
1286
1284
  : {};
@@ -2126,15 +2124,20 @@ function createFormControl(props = {}) {
2126
2124
  }
2127
2125
  }
2128
2126
  }
2129
- for (const fieldName of _names.mount) {
2130
- const value = get(values, fieldName, get(_defaultValues, fieldName));
2131
- if (!isUndefined(value)) {
2132
- set(values, fieldName, value);
2127
+ if (keepStateOptions.keepFieldsRef) {
2128
+ for (const fieldName of _names.mount) {
2133
2129
  setValue(fieldName, get(values, fieldName));
2134
2130
  }
2135
2131
  }
2132
+ else {
2133
+ _fields = {};
2134
+ }
2136
2135
  }
2137
- _formValues = cloneObject(values);
2136
+ _formValues = _options.shouldUnregister
2137
+ ? keepStateOptions.keepDefaultValues
2138
+ ? cloneObject(_defaultValues)
2139
+ : {}
2140
+ : cloneObject(values);
2138
2141
  _subjects.array.next({
2139
2142
  values: { ...values },
2140
2143
  });
@@ -2725,7 +2728,10 @@ function useForm(props = {}) {
2725
2728
  }, [control, formState.isDirty]);
2726
2729
  React__default.useEffect(() => {
2727
2730
  if (props.values && !deepEqual(props.values, _values.current)) {
2728
- control._reset(props.values, control._options.resetOptions);
2731
+ control._reset(props.values, {
2732
+ keepFieldsRef: true,
2733
+ ...control._options.resetOptions,
2734
+ });
2729
2735
  _values.current = props.values;
2730
2736
  updateFormState((state) => ({ ...state }));
2731
2737
  }