react-hook-form 7.42.0 → 7.42.1

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.
@@ -148,7 +148,8 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
148
148
 
149
149
  var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
150
150
 
151
- var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
151
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
152
+ updateFormState(formStateData);
152
153
  const { name, ...formState } = formStateData;
153
154
  return (isEmptyObject(formState) ||
154
155
  Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
@@ -231,7 +232,7 @@ function useFormState(props) {
231
232
  disabled,
232
233
  next: (value) => _mounted.current &&
233
234
  shouldSubscribeByName(_name.current, value.name, exact) &&
234
- shouldRenderFormState(value, _localProxyFormState.current) &&
235
+ shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
235
236
  updateFormState({
236
237
  ...control._formState,
237
238
  ...value,
@@ -246,7 +247,7 @@ function useFormState(props) {
246
247
  isDirty,
247
248
  });
248
249
  }
249
- control._updateValid();
250
+ _localProxyFormState.current.isValid && control._updateValid(true);
250
251
  return () => {
251
252
  _mounted.current = false;
252
253
  };
@@ -1117,7 +1118,7 @@ function useFieldArray(props) {
1117
1118
  control._names.focus &&
1118
1119
  focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus || ''));
1119
1120
  control._names.focus = '';
1120
- control._proxyFormState.isValid && control._updateValid();
1121
+ control._updateValid();
1121
1122
  }, [fields, name, control]);
1122
1123
  React.useEffect(() => {
1123
1124
  !get(control._formValues, name) && control._updateFieldArray(name);
@@ -1439,8 +1440,8 @@ function createFormControl(props = {}, flushRootRender) {
1439
1440
  clearTimeout(timer);
1440
1441
  timer = window.setTimeout(callback, wait);
1441
1442
  };
1442
- const _updateValid = async () => {
1443
- if (_proxyFormState.isValid) {
1443
+ const _updateValid = async (shouldUpdateValid) => {
1444
+ if (_proxyFormState.isValid || shouldUpdateValid) {
1444
1445
  const isValid = _options.resolver
1445
1446
  ? isEmptyObject((await _executeSchema()).errors)
1446
1447
  : await executeBuiltInValidation(_fields, true);
@@ -2143,6 +2144,12 @@ function createFormControl(props = {}, flushRootRender) {
2143
2144
  }
2144
2145
  }
2145
2146
  };
2147
+ const _updateFormState = (updatedFormState) => {
2148
+ _formState = {
2149
+ ..._formState,
2150
+ ...updatedFormState,
2151
+ };
2152
+ };
2146
2153
  if (isFunction(_options.defaultValues)) {
2147
2154
  _options.defaultValues().then((values) => {
2148
2155
  reset(values, _options.resetOptions);
@@ -2165,6 +2172,7 @@ function createFormControl(props = {}, flushRootRender) {
2165
2172
  _updateFieldArray,
2166
2173
  _getFieldArray,
2167
2174
  _reset,
2175
+ _updateFormState,
2168
2176
  _subjects,
2169
2177
  _proxyFormState,
2170
2178
  get _fields() {
@@ -2278,18 +2286,14 @@ function useForm(props = {}) {
2278
2286
  useSubscribe({
2279
2287
  subject: control._subjects.state,
2280
2288
  next: (value) => {
2281
- if (shouldRenderFormState(value, control._proxyFormState, true)) {
2282
- control._formState = {
2283
- ...control._formState,
2284
- ...value,
2285
- };
2289
+ if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
2286
2290
  updateFormState({ ...control._formState });
2287
2291
  }
2288
2292
  },
2289
2293
  });
2290
2294
  React.useEffect(() => {
2291
2295
  if (!control._stateFlags.mount) {
2292
- control._proxyFormState.isValid && control._updateValid();
2296
+ control._updateValid();
2293
2297
  control._stateFlags.mount = true;
2294
2298
  }
2295
2299
  if (control._stateFlags.watch) {