Download react-hook-form/src/logic/schemaErrorLookup.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/logic/schemaErrorLookup.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/logic/schemaErrorLookup.ts
-
curl -L -o schemaErrorLookup.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/logic/schemaErrorLookup.ts
1.07 kB
| import type { FieldError, FieldErrors, FieldValues } from '../types'; | |
| import get from '../utils/get'; | |
| import isKey from '../utils/isKey'; | |
| export default function schemaErrorLookup<T extends FieldValues = FieldValues>( | |
| errors: FieldErrors<T>, | |
| _fields: FieldValues, | |
| name: string, | |
| ): { | |
| error?: FieldError; | |
| name: string; | |
| } { | |
| const error = get(errors, name); | |
| if (error || isKey(name)) { | |
| return { | |
| error, | |
| name, | |
| }; | |
| } | |
| const names = name.split('.'); | |
| while (names.length) { | |
| const fieldName = names.join('.'); | |
| const field = get(_fields, fieldName); | |
| const foundError = get(errors, fieldName); | |
| if (field && !Array.isArray(field) && name !== fieldName) { | |
| return { name }; | |
| } | |
| if (foundError && foundError.type) { | |
| return { | |
| name: fieldName, | |
| error: foundError, | |
| }; | |
| } | |
| if (foundError && foundError.root && foundError.root.type) { | |
| return { | |
| name: `${fieldName}.root`, | |
| error: foundError.root, | |
| }; | |
| } | |
| names.pop(); | |
| } | |
| return { | |
| name, | |
| }; | |
| } | |