Replies: 6 comments 2 replies
-
Heya 👋🏻 Can you try this solution: import { yupResolver } from '@hookform/resolvers/yup';
import { useForm } from 'react-hook-form';
import * as yup from 'yup';
import type { ObjectSchema } from 'yup';
import type { InputHTMLAttributes } from 'react';
interface SchemaType1 {
test: string;
}
interface WrapperWithHookFormProps<T extends ObjectSchema<any>>
extends InputHTMLAttributes<HTMLInputElement> {
schema: T;
}
const schema1: ObjectSchema<SchemaType1> = yup.object({
test: yup.string().required(),
});
const WrapperWithHookForm = <T extends ObjectSchema<any>>({
schema,
...props
}: WrapperWithHookFormProps<T>): JSX.Element => {
const { register } = useForm<T>({ resolver: yupResolver(schema) });
return <input {...props} />;
}; |
Beta Was this translation helpful? Give feedback.
-
@jorisre Hey, thanks for the solution, but I actually need that Since it's working in |
Beta Was this translation helpful? Give feedback.
-
It probably breaks because of Yup v1 upgrade. Can you add more detail in your repro? To understand what you want to achieve? |
Beta Was this translation helpful? Give feedback.
-
Sure. I'll update the reprod. I've been using |
Beta Was this translation helpful? Give feedback.
-
@jorisre I've updated the reprod (it's another forked one): https://stackblitz.com/edit/vitejs-vite-ylobmg?file=src/__tests__/Demo.test.tsx |
Beta Was this translation helpful? Give feedback.
-
Moved your issue to discussion. It's not a react-hook-form|resolvers bug |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Hey, the Type error happened after upgrading to
v3.0.0
, and I'm using generic to create a wrapper withreact-hook-form
in my unit test.It's working as expected in
v2
To Reproduce
Open the link below, the error will be there
Stackblitz link
https://stackblitz.com/edit/vitejs-vite-ylobmg?file=src/__tests__/Demo.test.tsx
Expected behaviour
A clear and concise description of what you expected to happen.
Screenshots
Desktop (please complete the following information):
Beta Was this translation helpful? Give feedback.
All reactions