Next.js Discord

Discord Forum

I don't understand! Why we need schema validation library with react-hook forms, since We can do it

Unanswered
Argente Brun posted this in #help-forum
Open in Discord
Argente BrunOP
I don't understand! Why we need schema validation library with react-hook forms, since We can do it in react-hook-forms itself.


const schema = yup.object({ username: yup.string().required("Username is required"), email: yup .string() .email("Email format is not valid") .required("Email is required"), });

3 Replies

Usually you do this so that you can validate the data both on client side when the form gets filled out and on server side when you receive said data in an api endpoint with the same library and schema.

It's true that rhf already gives you the option to validate the inputs but it doesn't hurt using a specialised library for the job.
If you don't want to use yup or zod you don't have to, however it's generally a good idea and I suggest you try/learn using at least one of these libraries since they're useful in other scenarios too
i would say formik and yup works well