react-code-dataset / react-hook-form /src /logic /shouldRenderFormState.ts
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
833 Bytes
import { VALIDATION_MODE } from '../constants';
import type {
FieldValues,
FormState,
InternalFieldName,
ReadFormState,
} from '../types';
import isEmptyObject from '../utils/isEmptyObject';
export default <T extends FieldValues, K extends ReadFormState>(
formStateData: Partial<FormState<T>> & {
name?: InternalFieldName;
values?: T;
},
_proxyFormState: K,
updateFormState: (formState: Partial<FormState<T>>) => void,
isRoot?: boolean,
) => {
updateFormState(formStateData);
const { name, ...formState } = formStateData;
return (
isEmptyObject(formState) ||
Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
Object.keys(formState).find(
(key) =>
_proxyFormState[key as keyof ReadFormState] ===
(!isRoot || VALIDATION_MODE.all),
)
);
};