react-hook-form 7.19.3 → 7.19.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.
package/dist/index.esm.js CHANGED
@@ -177,33 +177,6 @@ function generateWatchOutput(names, _names, formValues, isGlobal) {
177
177
  return formValues;
178
178
  }
179
179
 
180
- var isKey = (value) => /^\w*$/.test(value);
181
-
182
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
183
-
184
- function set(object, path, value) {
185
- let index = -1;
186
- const tempPath = isKey(path) ? [path] : stringToPath(path);
187
- const length = tempPath.length;
188
- const lastIndex = length - 1;
189
- while (++index < length) {
190
- const key = tempPath[index];
191
- let newValue = value;
192
- if (index !== lastIndex) {
193
- const objValue = object[key];
194
- newValue =
195
- isObject(objValue) || Array.isArray(objValue)
196
- ? objValue
197
- : !isNaN(+tempPath[index + 1])
198
- ? []
199
- : {};
200
- }
201
- object[key] = newValue;
202
- object = object[key];
203
- }
204
- return object;
205
- }
206
-
207
180
  function useWatch(props) {
208
181
  const methods = useFormContext();
209
182
  const { control = methods.control, name, defaultValue, disabled, } = props || {};
@@ -215,9 +188,7 @@ function useWatch(props) {
215
188
  callback: (formState) => {
216
189
  if (shouldSubscribeByName(_name.current, formState.name)) {
217
190
  const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
218
- updateValue(isObject(fieldValues) &&
219
- !(isString(_name.current) &&
220
- get(control._fields, _name.current, {})._f)
191
+ updateValue(isUndefined(_name.current)
221
192
  ? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
222
193
  ? [...fieldValues]
223
194
  : fieldValues);
@@ -316,6 +287,33 @@ const Controller = (props) => props.render(useController(props));
316
287
  var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
317
288
  ? Object.assign(Object.assign({}, errors[name]), { types: Object.assign(Object.assign({}, (errors[name] && errors[name].types ? errors[name].types : {})), { [type]: message || true }) }) : {};
318
289
 
290
+ var isKey = (value) => /^\w*$/.test(value);
291
+
292
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
293
+
294
+ function set(object, path, value) {
295
+ let index = -1;
296
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
297
+ const length = tempPath.length;
298
+ const lastIndex = length - 1;
299
+ while (++index < length) {
300
+ const key = tempPath[index];
301
+ let newValue = value;
302
+ if (index !== lastIndex) {
303
+ const objValue = object[key];
304
+ newValue =
305
+ isObject(objValue) || Array.isArray(objValue)
306
+ ? objValue
307
+ : !isNaN(+tempPath[index + 1])
308
+ ? []
309
+ : {};
310
+ }
311
+ object[key] = newValue;
312
+ object = object[key];
313
+ }
314
+ return object;
315
+ }
316
+
319
317
  const focusFieldBy = (fields, callback, fieldsNames) => {
320
318
  for (const key of fieldsNames || Object.keys(fields)) {
321
319
  const field = get(fields, key);
@@ -433,7 +431,6 @@ const useFieldArray = (props) => {
433
431
  const updatedFieldArrayValues = omitKeys(updatedFieldArrayValuesWithKey, keyName);
434
432
  _actioned.current = true;
435
433
  set(control._formValues, name, updatedFieldArrayValues);
436
- setFields(updatedFieldArrayValuesWithKey);
437
434
  return updatedFieldArrayValues;
438
435
  }, [control, name, keyName]);
439
436
  const append$1 = (value, options) => {
@@ -442,6 +439,7 @@ const useFieldArray = (props) => {
442
439
  control._updateFieldArray(name, append, {
443
440
  argA: fillEmptyArray(value),
444
441
  }, updateValues(updatedFieldArrayValuesWithKey));
442
+ setFields(updatedFieldArrayValuesWithKey);
445
443
  control._names.focus = getFocusFieldName(name, updatedFieldArrayValuesWithKey.length - appendValue.length, options);
446
444
  };
447
445
  const prepend$1 = (value, options) => {
@@ -449,6 +447,7 @@ const useFieldArray = (props) => {
449
447
  control._updateFieldArray(name, prepend, {
450
448
  argA: fillEmptyArray(value),
451
449
  }, updateValues(updatedFieldArrayValuesWithKey));
450
+ setFields(updatedFieldArrayValuesWithKey);
452
451
  control._names.focus = getFocusFieldName(name, 0, options);
453
452
  };
454
453
  const remove = (index) => {
@@ -456,6 +455,7 @@ const useFieldArray = (props) => {
456
455
  control._updateFieldArray(name, removeArrayAt, {
457
456
  argA: index,
458
457
  }, updateValues(updatedFieldArrayValuesWithKey));
458
+ setFields(updatedFieldArrayValuesWithKey);
459
459
  };
460
460
  const insert$1 = (index, value, options) => {
461
461
  const updatedFieldArrayValuesWithKey = insert(mapCurrentIds(control._getFieldArray(name), _fieldIds, keyName), index, mapIds(convertToArrayPayload(value), keyName));
@@ -463,6 +463,7 @@ const useFieldArray = (props) => {
463
463
  argA: index,
464
464
  argB: fillEmptyArray(value),
465
465
  }, updateValues(updatedFieldArrayValuesWithKey));
466
+ setFields(updatedFieldArrayValuesWithKey);
466
467
  control._names.focus = getFocusFieldName(name, index, options);
467
468
  };
468
469
  const swap = (indexA, indexB) => {
@@ -472,6 +473,7 @@ const useFieldArray = (props) => {
472
473
  argA: indexA,
473
474
  argB: indexB,
474
475
  }, updateValues(updatedFieldArrayValuesWithKey), false);
476
+ setFields(updatedFieldArrayValuesWithKey);
475
477
  };
476
478
  const move = (from, to) => {
477
479
  const updatedFieldArrayValuesWithKey = mapCurrentIds(control._getFieldArray(name), _fieldIds, keyName);
@@ -480,6 +482,7 @@ const useFieldArray = (props) => {
480
482
  argA: from,
481
483
  argB: to,
482
484
  }, updateValues(updatedFieldArrayValuesWithKey), false);
485
+ setFields(updatedFieldArrayValuesWithKey);
483
486
  };
484
487
  const update = (index, value) => {
485
488
  const updatedFieldArrayValuesWithKey = mapCurrentIds(control._getFieldArray(name), _fieldIds, keyName);
@@ -489,10 +492,12 @@ const useFieldArray = (props) => {
489
492
  argA: index,
490
493
  argB: value,
491
494
  }, updateValues(_fieldIds.current), true, false);
495
+ setFields(_fieldIds.current);
492
496
  };
493
497
  const replace = (value) => {
494
498
  const updatedFieldArrayValuesWithKey = mapIds(convertToArrayPayload(value), keyName);
495
499
  control._updateFieldArray(name, () => updatedFieldArrayValuesWithKey, {}, updateValues(updatedFieldArrayValuesWithKey), true, false);
500
+ setFields(updatedFieldArrayValuesWithKey);
496
501
  };
497
502
  React.useEffect(() => {
498
503
  control._stateFlags.action = false;