100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Web

Yup

IntermediateTool2.5K learners

Yup is a JavaScript schema builder for value parsing and validation, commonly used to define validation rules for forms and API data through a chainable, declarative API.

Definition

Yup is a JavaScript schema builder for value parsing and validation, commonly used to define validation rules for forms and API data through a chainable, declarative API.

Overview

Yup lets developers describe the shape and constraints of an object — required fields, string formats, number ranges, nested objects, and arrays — using a chainable API such as `yup.object({ email: yup.string().email().required() })`. Once defined, a schema can validate a value asynchronously or synchronously and return either the parsed data or a collection of validation error messages. Yup predates the widespread adoption of TypeScript in the React ecosystem and was for years the default validation companion to Formik, which has first-class support for passing a Yup schema directly to its `validationSchema` prop. Its API is inspired by an earlier Node.js validation library, and it remains popular for its readable, method-chaining style. In newer TypeScript-first projects, Zod (web) has become a common alternative because it derives static types directly from the schema, whereas Yup schemas and TypeScript types must be defined and kept in sync separately (though `@types` and schema-to-type helpers narrow this gap). Yup nonetheless remains widely used in existing codebases and continues to work well with both Formik and React Hook Form via a dedicated resolver.

Key Features

  • Chainable schema API for strings, numbers, dates, objects, and arrays
  • Built-in validators for common patterns like email, URL, and min/max length
  • Support for conditional validation rules based on other field values
  • Synchronous and asynchronous validation methods
  • Deep support for nested objects and arrays of objects
  • Tight integration with Formik via the validationSchema prop
  • Resolver support for React Hook Form

Use Cases

Form validation schemas paired with Formik or React Hook Form
Validating request bodies in Node.js API routes
Enforcing consistent field rules (required, format, range) across a large form
Conditional validation, such as requiring a field only when another is set
Legacy React codebases that adopted Yup before Zod's popularity grew

Frequently Asked Questions