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

Function clearErrors

src/logic/createFormControl.ts:1100–1120  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

1098 });
1099
1100 const clearErrors: UseFormClearErrors<TFieldValues> = (name) => {
1101 const names = name ? convertToArrayPayload(name) : undefined;
1102
1103 names?.forEach((inputName) => unset(_formState.errors, inputName));
1104
1105 if (names) {
1106 // Emit for each cleared field with the field name so that
1107 // shouldSubscribeByName can filter and avoid broad re-renders
1108 names.forEach((inputName) => {
1109 _subjects.state.next({
1110 name: inputName,
1111 errors: _formState.errors,
1112 });
1113 });
1114 } else {
1115 // Clear all errors - emit without name to notify all subscribers
1116 _subjects.state.next({
1117 errors: {},
1118 });
1119 }
1120 };
1121
1122 const setError: UseFormSetError<TFieldValues> = (name, error, options) => {
1123 const ref = (get(_fields, name, { _f: {} })._f || {}).ref;

Callers 9

validateFormFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85
AppFunction · 0.85
ValidateFieldCriteriaFunction · 0.85
SetErrorFunction · 0.85
appendQuestionFunction · 0.85
appendQuestionFunction · 0.85

Calls 1

unsetFunction · 0.85

Tested by 4

AppFunction · 0.68
AppFunction · 0.68
ComponentFunction · 0.68
AppFunction · 0.68