Skip to content

Commit

Permalink
fix(useformstate): hotfix: we needed AnySchema<T> instead of SchemaOf…
Browse files Browse the repository at this point in the history
…<T> for the yup breaking change (migtools#59)

BREAKING CHANGE: useFormState and useFormField now require `yup.AnySchema<T>` schema types instead
of the `yup.SchemaOf<T>` which was not behaving correctly with boolean fields.
  • Loading branch information
mturley authored Apr 22, 2021
1 parent 626a934 commit a1e3601
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/hooks/useFormState/useFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface IFormField<T> {
isTouched: boolean;
setIsTouched: (isTouched: boolean) => void;
reset: () => void;
schema: yup.SchemaOf<T>;
schema: yup.AnySchema<T>;
}

export interface IValidatedFormField<T> extends IFormField<T> {
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface IFormState<TFieldValues> {

export const useFormField = <T>(
initialValue: T,
schema: yup.SchemaOf<T>,
schema: yup.AnySchema<T>,
options: { initialTouched?: boolean } = {}
): IFormField<T> => {
const [initializedValue, setInitializedValue] = React.useState<T>(initialValue);
Expand Down Expand Up @@ -109,7 +109,7 @@ export const useFormState = <TFieldValues>(
lastValuesRef.current = values;
const schemaShape = fieldKeys.reduce(
(newObj, key) => ({ ...newObj, [key]: fields[key].schema }),
{} as { [key in keyof TFieldValues]: yup.SchemaOf<TFieldValues[key]> }
{} as { [key in keyof TFieldValues]: yup.AnySchema<TFieldValues[key]> }
);
const schema = yup.object().shape(schemaShape);
setHasRunInitialValidation(true);
Expand Down

0 comments on commit a1e3601

Please sign in to comment.