Forms
Maybern uses React Hook Form with Yup/Zod schemas for form handling and validation.Basic Form
Validation Schemas
Yup Schema
Zod Schema
Form Fields
Standard Inputs
Number Inputs
Selection Inputs
Date Inputs
Error Handling
Field Errors
Server Errors
Form Patterns
Edit Form with Initial Data
Conditional Fields
Field Arrays
Best Practices
Define Schemas First
Define Schemas First
Create validation schemas before building forms. They serve as documentation and enforce consistency.
Type Inference
Type Inference
Use
yup.InferType or z.infer to derive form types from schemas.Controlled vs Uncontrolled
Controlled vs Uncontrolled
Prefer React Hook Form’s uncontrolled approach. Use
watch sparingly for dependent fields.Error Display
Error Display
Always show validation errors near the relevant field. Use FormField wrapper for consistent error display.