MCPcopy Index your code
hub / github.com/react-hook-form/react-hook-form / shouldRenderByError

Function shouldRenderByError

src/logic/createFormControl.ts:489–536  ·  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

487 };
488
489 const shouldRenderByError = (
490 name: InternalFieldName,
491 isValid?: boolean,
492 error?: FieldError,
493 fieldState?: {
494 dirty?: FieldNamesMarkedBoolean<TFieldValues>;
495 isDirty?: boolean;
496 touched?: FieldNamesMarkedBoolean<TFieldValues>;
497 },
498 ) => {
499 const previousFieldError = get(_formState.errors, name);
500 const shouldUpdateValid =
501 (_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
502 isBoolean(isValid) &&
503 _formState.isValid !== isValid;
504
505 if (_options.delayError && error) {
506 delayErrorCallback = debounce(() => updateErrors(name, error));
507 delayErrorCallback(_options.delayError);
508 } else {
509 clearTimeout(timer);
510 delayErrorCallback = null;
511 error
512 ? set(_formState.errors, name, error)
513 : unset(_formState.errors, name);
514 _formState.errors = { ..._formState.errors };
515 }
516
517 if (
518 (error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
519 !isEmptyObject(fieldState) ||
520 shouldUpdateValid
521 ) {
522 const updatedFormState = {
523 ...fieldState,
524 ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
525 errors: _formState.errors,
526 name,
527 };
528
529 _formState = {
530 ..._formState,
531 ...updatedFormState,
532 };
533
534 _subjects.state.next(updatedFormState);
535 }
536 };
537
538 const _runSchema = async (name?: InternalFieldName[]) => {
539 _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

Used in the wild real call sites across dependent graphs

searching dependent graphs…