'Why use yup validation?

There is a validation method provided by the react hook form. Nevertheless, some developers sometimes use yup validation. What I thought about seems to have the advantage of using schema validation together in the frontend and backend.
I wonder if there is anything else out of this.



Solution 1:[1]

I'm using zod as an external validation instead of yup ...

schema validation together in the frontend and backend.

Another big advantage is ...

  • Since the schema can be defined independently, unit testing can be done easily.
  • Since the schema can be defined independently, it is easy to understand as a validation definition.
  • Can handle complex validation

Complex validation is, for example, "when the validation of field A depends on the state of other fields B".

With zod, you can create complex validations across other fields, such as with?refine superRefine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rin