MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / shouldRenderByError

Function shouldRenderByError

src/logic/createFormControl.ts:416–462  ·  view source on GitHub ↗
(
    name: InternalFieldName,
    isValid?: boolean,
    error?: FieldError,
    fieldState?: {
      dirty?: FieldNamesMarkedBoolean<TFieldValues>;
      isDirty?: boolean;
      touched?: FieldNamesMarkedBoolean<TFieldValues>;
    },
  )

Source from the content-addressed store, hash-verified

414 };
415
416 const shouldRenderByError = (
417 name: InternalFieldName,
418 isValid?: boolean,
419 error?: FieldError,
420 fieldState?: {
421 dirty?: FieldNamesMarkedBoolean<TFieldValues>;
422 isDirty?: boolean;
423 touched?: FieldNamesMarkedBoolean<TFieldValues>;
424 },
425 ) => {
426 const previousFieldError = get(_formState.errors, name);
427 const shouldUpdateValid =
428 (_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
429 isBoolean(isValid) &&
430 _formState.isValid !== isValid;
431
432 if (_options.delayError && error) {
433 delayErrorCallback = debounce(() => updateErrors(name, error));
434 delayErrorCallback(_options.delayError);
435 } else {
436 clearTimeout(timer);
437 delayErrorCallback = null;
438 error
439 ? set(_formState.errors, name, error)
440 : unset(_formState.errors, name);
441 }
442
443 if (
444 (error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
445 !isEmptyObject(fieldState) ||
446 shouldUpdateValid
447 ) {
448 const updatedFormState = {
449 ...fieldState,
450 ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
451 errors: _formState.errors,
452 name,
453 };
454
455 _formState = {
456 ..._formState,
457 ...updatedFormState,
458 };
459
460 _subjects.state.next(updatedFormState);
461 }
462 };
463
464 const _runSchema = async (name?: InternalFieldName[]) => {
465 _updateIsValidating(name, true);

Callers 1

onChangeFunction · 0.85

Calls 4

debounceFunction · 0.85
updateErrorsFunction · 0.85
unsetFunction · 0.85
deepEqualFunction · 0.85

Tested by

no test coverage detected