| 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; |