| 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?: |