form-patterns

Automate React form handling with React Hook Form, Zod, and tRPC.

2|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/retrip-ai/agent-skills --skill form-patterns-retrip-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: form-patterns
Source: https://github.com/retrip-ai/agent-skills/tree/main/skills/form-patterns
Command: npx skills add https://github.com/retrip-ai/agent-skills --skill form-patterns-retrip-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a structured approach to building robust, maintainable forms in React using React Hook Form and Zod validation. It covers common patterns for creating, editing, and validating forms, including support for dynamic fields and server mutations.

Core Features & Use Cases

  • Form setup & validation using RHF + Zod resolvers to enforce schemas and defaults.
  • Edit forms with unsaved changes using useFormState and an UnsavedChangesBar for a safe UX.
  • Array and dynamic fields with useFieldArray to manage lists of inputs like emails or tags.
  • tRPC integration for submitting form data and handling server responses with proper error handling and query invalidation.
  • Field components using Field, FieldLabel, FieldError, Input, Select, and other UI primitives for accessibility.

Quick Start

Create a basic form using React Hook Form and Zod with fields email and password and basic validation. Then extend to an array field and an edit form with unsaved changes.

Frequently Asked Questions about form-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle unsaved changes in a React Hook Form edit form?

Handle unsaved changes in React Hook Form by tracking form state with useFormState and implementing an UnsavedChangesBar component to provide a safe user experience before navigation or server mutations.

What is the best way to validate dynamic array fields in React forms?

Validate dynamic array fields in React forms by combining React Hook Form's useFieldArray with Zod schema resolvers to enforce validation rules and manage lists of inputs like emails or tags.

How do I submit React Hook Form data using tRPC mutations?

Submit React Hook Form data using tRPC mutations by wiring your form's onSubmit handler to the tRPC mutation function, managing server responses, and executing query invalidation upon successful submission.

Can I use Zod with React Hook Form for schema validation?

You can use Zod with React Hook Form for schema validation by integrating a resolver library like @hookform/resolvers/zod to enforce schemas and define default values directly.

What UI primitives are needed for accessible React form fields?

Accessible React form fields require UI primitives like Field, FieldLabel, FieldError, Input, and Select components, managed via the Controller component to maintain consistent state and error handling.

Do I need a resolver library to connect Zod schemas to React Hook Form?

You need a resolver library like @hookform/resolvers to connect Zod schemas to React Hook Form, translating schema validation rules into the form's internal validation format.