Download react-hook-form/src/logic/getProxyFormState.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 963 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/logic/getProxyFormState.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/logic/getProxyFormState.ts
-
curl -L -o getProxyFormState.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/logic/getProxyFormState.ts
963 Bytes
| import { VALIDATION_MODE } from '../constants'; | |
| import type { Control, FieldValues, FormState, ReadFormState } from '../types'; | |
| export default < | |
| TFieldValues extends FieldValues, | |
| TContext = any, | |
| TTransformedValues = TFieldValues, | |
| >( | |
| formState: FormState<TFieldValues>, | |
| control: Control<TFieldValues, TContext, TTransformedValues>, | |
| localProxyFormState?: ReadFormState, | |
| isRoot = true, | |
| ) => { | |
| const result = { | |
| defaultValues: control._defaultValues, | |
| } as typeof formState; | |
| for (const key in formState) { | |
| Object.defineProperty(result, key, { | |
| get: () => { | |
| const _key = key as keyof FormState<TFieldValues> & keyof ReadFormState; | |
| if (control._proxyFormState[_key] !== VALIDATION_MODE.all) { | |
| control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all; | |
| } | |
| localProxyFormState && (localProxyFormState[_key] = true); | |
| return formState[_key]; | |
| }, | |
| }); | |
| } | |
| return result; | |
| }; | |