From a1e360186d48f8d15252b4108f9b6e6a377a1ac5 Mon Sep 17 00:00:00 2001 From: Mike Turley Date: Thu, 22 Apr 2021 18:49:44 -0400 Subject: [PATCH] fix(useformstate): hotfix: we needed AnySchema instead of SchemaOf for the yup breaking change (#59) BREAKING CHANGE: useFormState and useFormField now require `yup.AnySchema` schema types instead of the `yup.SchemaOf` which was not behaving correctly with boolean fields. --- src/hooks/useFormState/useFormState.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/useFormState/useFormState.ts b/src/hooks/useFormState/useFormState.ts index d2a4260..64e6fe7 100644 --- a/src/hooks/useFormState/useFormState.ts +++ b/src/hooks/useFormState/useFormState.ts @@ -12,7 +12,7 @@ export interface IFormField { isTouched: boolean; setIsTouched: (isTouched: boolean) => void; reset: () => void; - schema: yup.SchemaOf; + schema: yup.AnySchema; } export interface IValidatedFormField extends IFormField { @@ -52,7 +52,7 @@ export interface IFormState { export const useFormField = ( initialValue: T, - schema: yup.SchemaOf, + schema: yup.AnySchema, options: { initialTouched?: boolean } = {} ): IFormField => { const [initializedValue, setInitializedValue] = React.useState(initialValue); @@ -109,7 +109,7 @@ export const useFormState = ( lastValuesRef.current = values; const schemaShape = fieldKeys.reduce( (newObj, key) => ({ ...newObj, [key]: fields[key].schema }), - {} as { [key in keyof TFieldValues]: yup.SchemaOf } + {} as { [key in keyof TFieldValues]: yup.AnySchema } ); const schema = yup.object().shape(schemaShape); setHasRunInitialValidation(true);