Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the 'shape' function do in yup?

Most Yup examples use the shape method, but I find the documentation a little hard to understand why this is the case, and exactly what the method does.

Can someone please explain the difference between a schema defined with Yup.object({...}) and Yup.object().shape({...})?

like image 750
cubabit Avatar asked May 24 '20 19:05

cubabit


1 Answers

You can also pass a shape to the object constructor as a convenience.
yupobject documentation

Basically passing the schema to shape is just the long-form of passing it to the object constructor. Shape does however offer the benefit of chaining and overloading definitions in later chained methods. See yup.shape documentation

like image 188
Mastacheata Avatar answered Oct 19 '22 07:10

Mastacheata