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

Function setError

src/logic/createFormControl.ts:1122–1142  ·  view source on GitHub ↗
(name, error, options)

Source from the content-addressed store, hash-verified

1120 };
1121
1122 const setError: UseFormSetError<TFieldValues> = (name, error, options) => {
1123 const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1124 const currentError = get(_formState.errors, name) || {};
1125
1126 // Don't override existing error messages elsewhere in the object tree.
1127 const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
1128
1129 set(_formState.errors, name, {
1130 ...restOfErrorTree,
1131 ...error,
1132 ref,
1133 });
1134
1135 _subjects.state.next({
1136 name,
1137 errors: _formState.errors,
1138 isValid: false,
1139 });
1140
1141 options && options.shouldFocus && ref && ref.focus && ref.focus();
1142 };
1143
1144 const watch: UseFormWatch<TFieldValues> = (
1145 name?:

Callers 15

validateFormFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85
FormFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
AppFunction · 0.85
MyFormFunction · 0.85
ComponentFunction · 0.85
AppFunction · 0.85
ValidateFieldCriteriaFunction · 0.85

Calls

no outgoing calls

Tested by 10

AppFunction · 0.68
ComponentFunction · 0.68
FormFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
AppFunction · 0.68
MyFormFunction · 0.68
ComponentFunction · 0.68
AppFunction · 0.68