MCPcopy
hub / github.com/react-hook-form/react-hook-form / schemaErrorLookup

Function schemaErrorLookup

src/logic/schemaErrorLookup.ts:5–53  ·  view source on GitHub ↗
(
  errors: FieldErrors<T>,
  _fields: FieldValues,
  name: string,
)

Source from the content-addressed store, hash-verified

3import isKey from '../utils/isKey';
4
5export default function schemaErrorLookup<T extends FieldValues = FieldValues>(
6 errors: FieldErrors<T>,
7 _fields: FieldValues,
8 name: string,
9): {
10 error?: FieldError;
11 name: string;
12} {
13 const error = get(errors, name);
14
15 if (error || isKey(name)) {
16 return {
17 error,
18 name,
19 };
20 }
21
22 const names = name.split('.');
23
24 while (names.length) {
25 const fieldName = names.join('.');
26 const field = get(_fields, fieldName);
27 const foundError = get(errors, fieldName);
28
29 if (field && !Array.isArray(field) && name !== fieldName) {
30 return { name };
31 }
32
33 if (foundError && foundError.type) {
34 return {
35 name: fieldName,
36 error: foundError,
37 };
38 }
39
40 if (foundError && foundError.root && foundError.root.type) {
41 return {
42 name: `${fieldName}.root`,
43 error: foundError.root,
44 };
45 }
46
47 names.pop();
48 }
49
50 return {
51 name,
52 };
53}

Callers 2

onChangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…