react-hook-form 7.40.0-next.1 → 7.41.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.
Files changed (102) hide show
  1. package/dist/__tests__/controller.server.test.d.ts +2 -0
  2. package/dist/__tests__/controller.server.test.d.ts.map +1 -0
  3. package/dist/__tests__/controller.test.d.ts +2 -0
  4. package/dist/__tests__/controller.test.d.ts.map +1 -0
  5. package/dist/__tests__/logic/validateField.test.d.ts +2 -0
  6. package/dist/__tests__/logic/validateField.test.d.ts.map +1 -0
  7. package/dist/__tests__/type.test.d.ts +2 -0
  8. package/dist/__tests__/type.test.d.ts.map +1 -0
  9. package/dist/__tests__/useController.test.d.ts +2 -0
  10. package/dist/__tests__/useController.test.d.ts.map +1 -0
  11. package/dist/__tests__/useFieldArray/append.test.d.ts +2 -0
  12. package/dist/__tests__/useFieldArray/append.test.d.ts.map +1 -0
  13. package/dist/__tests__/useFieldArray/focus.test.d.ts +2 -0
  14. package/dist/__tests__/useFieldArray/focus.test.d.ts.map +1 -0
  15. package/dist/__tests__/useFieldArray/insert.test.d.ts +2 -0
  16. package/dist/__tests__/useFieldArray/insert.test.d.ts.map +1 -0
  17. package/dist/__tests__/useFieldArray/move.test.d.ts +2 -0
  18. package/dist/__tests__/useFieldArray/move.test.d.ts.map +1 -0
  19. package/dist/__tests__/useFieldArray/prepend.test.d.ts +2 -0
  20. package/dist/__tests__/useFieldArray/prepend.test.d.ts.map +1 -0
  21. package/dist/__tests__/useFieldArray/remove.test.d.ts +2 -0
  22. package/dist/__tests__/useFieldArray/remove.test.d.ts.map +1 -0
  23. package/dist/__tests__/useFieldArray/replace.test.d.ts +2 -0
  24. package/dist/__tests__/useFieldArray/replace.test.d.ts.map +1 -0
  25. package/dist/__tests__/useFieldArray/swap.test.d.ts +2 -0
  26. package/dist/__tests__/useFieldArray/swap.test.d.ts.map +1 -0
  27. package/dist/__tests__/useFieldArray/update.test.d.ts +2 -0
  28. package/dist/__tests__/useFieldArray/update.test.d.ts.map +1 -0
  29. package/dist/__tests__/useFieldArray.test.d.ts +2 -0
  30. package/dist/__tests__/useFieldArray.test.d.ts.map +1 -0
  31. package/dist/__tests__/useForm/clearErrors.test.d.ts +2 -0
  32. package/dist/__tests__/useForm/clearErrors.test.d.ts.map +1 -0
  33. package/dist/__tests__/useForm/formState.test.d.ts +2 -0
  34. package/dist/__tests__/useForm/formState.test.d.ts.map +1 -0
  35. package/dist/__tests__/useForm/getFieldState.test.d.ts +2 -0
  36. package/dist/__tests__/useForm/getFieldState.test.d.ts.map +1 -0
  37. package/dist/__tests__/useForm/getValues.test.d.ts +2 -0
  38. package/dist/__tests__/useForm/getValues.test.d.ts.map +1 -0
  39. package/dist/__tests__/useForm/handleSubmit.test.d.ts +2 -0
  40. package/dist/__tests__/useForm/handleSubmit.test.d.ts.map +1 -0
  41. package/dist/__tests__/useForm/register.test.d.ts +2 -0
  42. package/dist/__tests__/useForm/register.test.d.ts.map +1 -0
  43. package/dist/__tests__/useForm/reset.test.d.ts +2 -0
  44. package/dist/__tests__/useForm/reset.test.d.ts.map +1 -0
  45. package/dist/__tests__/useForm/resetField.test.d.ts +2 -0
  46. package/dist/__tests__/useForm/resetField.test.d.ts.map +1 -0
  47. package/dist/__tests__/useForm/resolver.test.d.ts +2 -0
  48. package/dist/__tests__/useForm/resolver.test.d.ts.map +1 -0
  49. package/dist/__tests__/useForm/setError.test.d.ts +2 -0
  50. package/dist/__tests__/useForm/setError.test.d.ts.map +1 -0
  51. package/dist/__tests__/useForm/setValue.test.d.ts +2 -0
  52. package/dist/__tests__/useForm/setValue.test.d.ts.map +1 -0
  53. package/dist/__tests__/useForm/trigger.test.d.ts +2 -0
  54. package/dist/__tests__/useForm/trigger.test.d.ts.map +1 -0
  55. package/dist/__tests__/useForm/unregister.test.d.ts +2 -0
  56. package/dist/__tests__/useForm/unregister.test.d.ts.map +1 -0
  57. package/dist/__tests__/useForm/watch.test.d.ts +2 -0
  58. package/dist/__tests__/useForm/watch.test.d.ts.map +1 -0
  59. package/dist/__tests__/useForm.server.test.d.ts +2 -0
  60. package/dist/__tests__/useForm.server.test.d.ts.map +1 -0
  61. package/dist/__tests__/useForm.test.d.ts +2 -0
  62. package/dist/__tests__/useForm.test.d.ts.map +1 -0
  63. package/dist/__tests__/useFormContext.server.test.d.ts +2 -0
  64. package/dist/__tests__/useFormContext.server.test.d.ts.map +1 -0
  65. package/dist/__tests__/useFormContext.test.d.ts +2 -0
  66. package/dist/__tests__/useFormContext.test.d.ts.map +1 -0
  67. package/dist/__tests__/useFormState.test.d.ts +2 -0
  68. package/dist/__tests__/useFormState.test.d.ts.map +1 -0
  69. package/dist/__tests__/useWatch.test.d.ts +2 -0
  70. package/dist/__tests__/useWatch.test.d.ts.map +1 -0
  71. package/dist/controller.d.ts +1 -1
  72. package/dist/controller.d.ts.map +1 -1
  73. package/dist/index.cjs.js +1 -1
  74. package/dist/index.cjs.js.map +1 -1
  75. package/dist/index.esm.mjs +64 -75
  76. package/dist/index.esm.mjs.map +1 -1
  77. package/dist/index.umd.js +1 -1
  78. package/dist/index.umd.js.map +1 -1
  79. package/dist/logic/createFormControl.d.ts +25 -2
  80. package/dist/logic/createFormControl.d.ts.map +1 -1
  81. package/dist/logic/getProxyFormState.d.ts +1 -1
  82. package/dist/logic/getProxyFormState.d.ts.map +1 -1
  83. package/dist/{utils → logic}/getValidationModes.d.ts +0 -0
  84. package/dist/{utils → logic}/getValidationModes.d.ts.map +1 -1
  85. package/dist/logic/updateFieldArrayRootError.d.ts +1 -1
  86. package/dist/logic/updateFieldArrayRootError.d.ts.map +1 -1
  87. package/dist/logic/validateField.d.ts.map +1 -1
  88. package/dist/types/errors.d.ts +2 -2
  89. package/dist/types/errors.d.ts.map +1 -1
  90. package/dist/types/form.d.ts +8 -8
  91. package/dist/types/form.d.ts.map +1 -1
  92. package/dist/types/path/eager.d.ts +5 -5
  93. package/dist/types/path/eager.d.ts.map +1 -1
  94. package/dist/types/utils.d.ts +1 -1
  95. package/dist/types/utils.d.ts.map +1 -1
  96. package/dist/types/validator.d.ts +1 -1
  97. package/dist/types/validator.d.ts.map +1 -1
  98. package/dist/useForm.d.ts.map +1 -1
  99. package/dist/useFormContext.d.ts +2 -1
  100. package/dist/useFormContext.d.ts.map +1 -1
  101. package/dist/useFormState.d.ts.map +1 -1
  102. package/package.json +20 -20
@@ -122,7 +122,10 @@ const useFormContext = () => React.useContext(HookFormContext);
122
122
  * }
123
123
  * ```
124
124
  */
125
- const FormProvider = ({ children, ...data }) => (React.createElement(HookFormContext.Provider, { value: React.useState(data)[0] }, children));
125
+ const FormProvider = (props) => {
126
+ const { children, ...data } = props;
127
+ return (React.createElement(HookFormContext.Provider, { value: data }, children));
128
+ };
126
129
 
127
130
  var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
128
131
  const result = {
@@ -215,6 +218,7 @@ function useFormState(props) {
215
218
  const _mounted = React.useRef(true);
216
219
  const _localProxyFormState = React.useRef({
217
220
  isDirty: false,
221
+ isLoading: false,
218
222
  dirtyFields: false,
219
223
  touchedFields: false,
220
224
  isValidating: false,
@@ -260,7 +264,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal) => {
260
264
  if (Array.isArray(names)) {
261
265
  return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
262
266
  }
263
- _names.watchAll = !!isGlobal;
267
+ isGlobal && (_names.watchAll = true);
264
268
  return formValues;
265
269
  };
266
270
 
@@ -327,17 +331,11 @@ function useWatch(props) {
327
331
  next: (formState) => {
328
332
  if (shouldSubscribeByName(_name.current, formState.name, exact)) {
329
333
  const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
330
- updateValue(isUndefined(_name.current) || !isUndefined(fieldValues)
331
- ? cloneObject(fieldValues)
332
- : isUndefined(fieldValues)
333
- ? defaultValue
334
- : fieldValues);
334
+ updateValue(isUndefined(fieldValues) ? defaultValue : cloneObject(fieldValues));
335
335
  }
336
336
  },
337
337
  });
338
- const [value, updateValue] = React.useState(isUndefined(defaultValue)
339
- ? control._getWatch(name)
340
- : defaultValue);
338
+ const [value, updateValue] = React.useState(control._getWatch(name, defaultValue));
341
339
  React.useEffect(() => control._removeUnmounted());
342
340
  return value;
343
341
  }
@@ -569,6 +567,14 @@ var getFocusFieldName = (name, index, options = {}) => options.shouldFocus || is
569
567
  `${name}.${isUndefined(options.focusIndex) ? index : options.focusIndex}.`
570
568
  : '';
571
569
 
570
+ var getValidationModes = (mode) => ({
571
+ isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
572
+ isOnBlur: mode === VALIDATION_MODE.onBlur,
573
+ isOnChange: mode === VALIDATION_MODE.onChange,
574
+ isOnAll: mode === VALIDATION_MODE.all,
575
+ isOnTouch: mode === VALIDATION_MODE.onTouched,
576
+ });
577
+
572
578
  var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
573
579
  (_names.watchAll ||
574
580
  _names.watch.has(name) ||
@@ -667,7 +673,9 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
667
673
  const isRadio = isRadioInput(ref);
668
674
  const isCheckBox = isCheckBoxInput(ref);
669
675
  const isRadioOrCheckbox = isRadio || isCheckBox;
670
- const isEmpty = ((valueAsNumber || isFileInput(ref)) && !ref.value) ||
676
+ const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
677
+ isUndefined(ref.value) &&
678
+ isUndefined(inputValue)) ||
671
679
  inputValue === '' ||
672
680
  (Array.isArray(inputValue) && !inputValue.length);
673
681
  const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
@@ -832,14 +840,6 @@ function append(data, value) {
832
840
 
833
841
  var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
834
842
 
835
- var getValidationModes = (mode) => ({
836
- isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
837
- isOnBlur: mode === VALIDATION_MODE.onBlur,
838
- isOnChange: mode === VALIDATION_MODE.onChange,
839
- isOnAll: mode === VALIDATION_MODE.all,
840
- isOnTouch: mode === VALIDATION_MODE.onTouched,
841
- });
842
-
843
843
  function insert(data, index, value) {
844
844
  return [
845
845
  ...data.slice(0, index),
@@ -1115,7 +1115,7 @@ function useFieldArray(props) {
1115
1115
  values: control._formValues,
1116
1116
  });
1117
1117
  control._names.focus &&
1118
- focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus));
1118
+ focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus || ''));
1119
1119
  control._names.focus = '';
1120
1120
  control._proxyFormState.isValid && control._updateValid();
1121
1121
  }, [fields, name, control]);
@@ -1386,7 +1386,7 @@ const defaultOptions = {
1386
1386
  reValidateMode: VALIDATION_MODE.onChange,
1387
1387
  shouldFocusError: true,
1388
1388
  };
1389
- function createFormControl(props = {}) {
1389
+ function createFormControl(props = {}, flushRootRender) {
1390
1390
  let _options = {
1391
1391
  ...defaultOptions,
1392
1392
  ...props,
@@ -1395,6 +1395,7 @@ function createFormControl(props = {}) {
1395
1395
  let _formState = {
1396
1396
  submitCount: 0,
1397
1397
  isDirty: false,
1398
+ isLoading: true,
1398
1399
  isValidating: false,
1399
1400
  isSubmitted: false,
1400
1401
  isSubmitting: false,
@@ -1424,7 +1425,6 @@ function createFormControl(props = {}) {
1424
1425
  };
1425
1426
  let delayErrorCallback;
1426
1427
  let timer = 0;
1427
- let validateFields = {};
1428
1428
  const _proxyFormState = {
1429
1429
  isDirty: false,
1430
1430
  dirtyFields: false,
@@ -1449,7 +1449,7 @@ function createFormControl(props = {}) {
1449
1449
  if (_proxyFormState.isValid) {
1450
1450
  const isValid = _options.resolver
1451
1451
  ? isEmptyObject((await _executeSchema()).errors)
1452
- : (await executeBuiltInValidation(_fields, true)).valid;
1452
+ : await executeBuiltInValidation(_fields, true);
1453
1453
  if (isValid !== _formState.isValid) {
1454
1454
  _formState.isValid = isValid;
1455
1455
  _subjects.state.next({
@@ -1458,6 +1458,10 @@ function createFormControl(props = {}) {
1458
1458
  }
1459
1459
  }
1460
1460
  };
1461
+ const _updateIsValidating = (value) => _proxyFormState.isValidating &&
1462
+ _subjects.state.next({
1463
+ isValidating: value,
1464
+ });
1461
1465
  const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1462
1466
  if (args && method) {
1463
1467
  _stateFlags.action = true;
@@ -1481,6 +1485,7 @@ function createFormControl(props = {}) {
1481
1485
  _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
1482
1486
  }
1483
1487
  _subjects.state.next({
1488
+ name,
1484
1489
  isDirty: _getDirty(name, values),
1485
1490
  dirtyFields: _formState.dirtyFields,
1486
1491
  errors: _formState.errors,
@@ -1515,12 +1520,12 @@ function createFormControl(props = {}) {
1515
1520
  const output = {
1516
1521
  name,
1517
1522
  };
1518
- if (_proxyFormState.isDirty) {
1519
- isPreviousDirty = _formState.isDirty;
1520
- _formState.isDirty = output.isDirty = _getDirty();
1521
- shouldUpdateField = isPreviousDirty !== output.isDirty;
1522
- }
1523
1523
  if (!isBlurEvent || shouldDirty) {
1524
+ if (_proxyFormState.isDirty) {
1525
+ isPreviousDirty = _formState.isDirty;
1526
+ _formState.isDirty = output.isDirty = _getDirty();
1527
+ shouldUpdateField = isPreviousDirty !== output.isDirty;
1528
+ }
1524
1529
  const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1525
1530
  isPreviousDirty = get(_formState.dirtyFields, name);
1526
1531
  isCurrentFieldPristine
@@ -1577,18 +1582,9 @@ function createFormControl(props = {}) {
1577
1582
  };
1578
1583
  _subjects.state.next(updatedFormState);
1579
1584
  }
1580
- validateFields[name]--;
1581
- if (_proxyFormState.isValidating &&
1582
- !Object.values(validateFields).some((v) => v)) {
1583
- _subjects.state.next({
1584
- isValidating: false,
1585
- });
1586
- validateFields = {};
1587
- }
1585
+ _updateIsValidating(false);
1588
1586
  };
1589
- const _executeSchema = async (name) => _options.resolver
1590
- ? await _options.resolver({ ..._formValues }, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
1591
- : {};
1587
+ const _executeSchema = async (name) => await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1592
1588
  const executeSchemaAndUpdateState = async (names) => {
1593
1589
  const { errors } = await _executeSchema();
1594
1590
  if (names) {
@@ -1615,9 +1611,6 @@ function createFormControl(props = {}) {
1615
1611
  const isFieldArrayRoot = _names.array.has(_f.name);
1616
1612
  const fieldError = await validateField(field, get(_formValues, _f.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation, isFieldArrayRoot);
1617
1613
  if (fieldError[_f.name]) {
1618
- if (_f.name === context.name) {
1619
- context.error = fieldError[context.name];
1620
- }
1621
1614
  context.valid = false;
1622
1615
  if (shouldOnlyCheckValid) {
1623
1616
  break;
@@ -1634,7 +1627,7 @@ function createFormControl(props = {}) {
1634
1627
  (await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
1635
1628
  }
1636
1629
  }
1637
- return context;
1630
+ return context.valid;
1638
1631
  };
1639
1632
  const _removeUnmounted = () => {
1640
1633
  for (const name of _names.unMount) {
@@ -1748,17 +1741,17 @@ function createFormControl(props = {}) {
1748
1741
  _subjects.watch.next({
1749
1742
  name,
1750
1743
  });
1744
+ !_stateFlags.mount && flushRootRender();
1751
1745
  };
1752
1746
  const onChange = async (event) => {
1753
1747
  const target = event.target;
1754
1748
  let name = target.name;
1755
1749
  const field = get(_fields, name);
1750
+ const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1756
1751
  if (field) {
1757
1752
  let error;
1758
1753
  let isValid;
1759
- const fieldValue = target.type
1760
- ? getFieldValue(field._f)
1761
- : getEventValue(event);
1754
+ const fieldValue = getCurrentFieldValue();
1762
1755
  const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1763
1756
  const shouldSkipValidation = (!hasValidation(field._f) &&
1764
1757
  !_options.resolver &&
@@ -1787,12 +1780,7 @@ function createFormControl(props = {}) {
1787
1780
  _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1788
1781
  }
1789
1782
  !isBlurEvent && watched && _subjects.state.next({});
1790
- validateFields[name] = validateFields[name]
1791
- ? validateFields[name] + 1
1792
- : 1;
1793
- _subjects.state.next({
1794
- isValidating: true,
1795
- });
1783
+ _updateIsValidating(true);
1796
1784
  if (_options.resolver) {
1797
1785
  const { errors } = await _executeSchema([name]);
1798
1786
  const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
@@ -1802,30 +1790,29 @@ function createFormControl(props = {}) {
1802
1790
  isValid = isEmptyObject(errors);
1803
1791
  }
1804
1792
  else {
1805
- if (_proxyFormState.isValid) {
1806
- const buildInValidationResult = await executeBuiltInValidation(_fields, true, {
1807
- name,
1808
- valid: true,
1809
- });
1810
- error = buildInValidationResult.error || {};
1811
- isValid = buildInValidationResult.valid;
1793
+ error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1794
+ if (error) {
1795
+ isValid = false;
1812
1796
  }
1813
- if (!error || isEmptyObject(error)) {
1814
- error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1797
+ else if (_proxyFormState.isValid) {
1798
+ isValid = await executeBuiltInValidation(_fields, true);
1815
1799
  }
1816
1800
  }
1817
- field._f.deps &&
1818
- trigger(field._f.deps);
1819
- shouldRenderByError(name, isValid, error, fieldState);
1801
+ if (!isPrimitive(fieldValue) || getCurrentFieldValue() === fieldValue) {
1802
+ field._f.deps &&
1803
+ trigger(field._f.deps);
1804
+ shouldRenderByError(name, isValid, error, fieldState);
1805
+ }
1806
+ else {
1807
+ _updateIsValidating(false);
1808
+ }
1820
1809
  }
1821
1810
  };
1822
1811
  const trigger = async (name, options = {}) => {
1823
1812
  let isValid;
1824
1813
  let validationResult;
1825
1814
  const fieldNames = convertToArrayPayload(name);
1826
- _subjects.state.next({
1827
- isValidating: true,
1828
- });
1815
+ _updateIsValidating(true);
1829
1816
  if (_options.resolver) {
1830
1817
  const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1831
1818
  isValid = isEmptyObject(errors);
@@ -1836,13 +1823,12 @@ function createFormControl(props = {}) {
1836
1823
  else if (name) {
1837
1824
  validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
1838
1825
  const field = get(_fields, fieldName);
1839
- return (await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field)).valid;
1826
+ return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
1840
1827
  }))).every(Boolean);
1841
1828
  !(!validationResult && !_formState.isValid) && _updateValid();
1842
1829
  }
1843
1830
  else {
1844
- validationResult = isValid = (await executeBuiltInValidation(_fields))
1845
- .valid;
1831
+ validationResult = isValid = await executeBuiltInValidation(_fields);
1846
1832
  }
1847
1833
  _subjects.state.next({
1848
1834
  ...(!isString(name) ||
@@ -1898,7 +1884,7 @@ function createFormControl(props = {}) {
1898
1884
  };
1899
1885
  const watch = (name, defaultValue) => isFunction(name)
1900
1886
  ? _subjects.watch.subscribe({
1901
- next: (info) => name(_getWatch(undefined, defaultValue), info),
1887
+ next: (payload) => name(_getWatch(undefined, defaultValue), payload),
1902
1888
  })
1903
1889
  : _getWatch(name, defaultValue, true);
1904
1890
  const unregister = (name, options = {}) => {
@@ -1983,9 +1969,7 @@ function createFormControl(props = {}) {
1983
1969
  refs: [
1984
1970
  ...refs.filter(live),
1985
1971
  fieldRef,
1986
- ...(!!Array.isArray(get(_defaultValues, name))
1987
- ? [{}]
1988
- : []),
1972
+ ...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
1989
1973
  ],
1990
1974
  ref: { type: fieldRef.type, name },
1991
1975
  }
@@ -2138,6 +2122,7 @@ function createFormControl(props = {}) {
2138
2122
  watchAll: false,
2139
2123
  focus: '',
2140
2124
  };
2125
+ !_stateFlags.mount && flushRootRender();
2141
2126
  _stateFlags.mount =
2142
2127
  !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
2143
2128
  _stateFlags.watch = !!props.shouldUnregister;
@@ -2184,6 +2169,9 @@ function createFormControl(props = {}) {
2184
2169
  if (isFunction(_options.defaultValues)) {
2185
2170
  _options.defaultValues().then((values) => {
2186
2171
  reset(values, _options.resetOptions);
2172
+ _subjects.state.next({
2173
+ isLoading: false,
2174
+ });
2187
2175
  });
2188
2176
  }
2189
2177
  return {
@@ -2289,6 +2277,7 @@ function useForm(props = {}) {
2289
2277
  const [formState, updateFormState] = React.useState({
2290
2278
  isDirty: false,
2291
2279
  isValidating: false,
2280
+ isLoading: true,
2292
2281
  isSubmitted: false,
2293
2282
  isSubmitting: false,
2294
2283
  isSubmitSuccessful: false,
@@ -2303,7 +2292,7 @@ function useForm(props = {}) {
2303
2292
  });
2304
2293
  if (!_formControl.current) {
2305
2294
  _formControl.current = {
2306
- ...createFormControl(props),
2295
+ ...createFormControl(props, () => updateFormState((formState) => ({ ...formState }))),
2307
2296
  formState,
2308
2297
  };
2309
2298
  }