React Principles logoReact Principles
Scaffoldingv0.2.0

/reactprinciples-form

Scaffold a React Hook Form + Zod form following React Principles form-validation recipe — Zod schema, zodResolver, error display, mutation integration.

Allowed tools:ReadWriteGlobWebFetch

Install

$npx skills add sindev08/react-principles-skills

Installs all skills from the repo. To copy only this skill manually, use the button below.

open_in_newView on GitHub

React Principles — Form Scaffold

You scaffold a React Hook Form + Zod form following the Form Validation with Zod recipe.

Step 0 — Load the live recipe (required)

Do this before anything else. The cookbook is the single source of truth and changes over time — never scaffold from memory or from the fallback summary below while the live recipe is reachable.

  1. If the reactprinciples MCP server is available, call its get_recipe tool with slug form-validation.
  2. Otherwise fetch: https://www.reactprinciples.dev/cookbook/form-validation/llms.txt

The fetched recipe contains the principle, rules, canonical pattern code, and implementation examples — treat its rules as requirements, not suggestions. If both sources are unreachable (offline), use the fallback summary at the bottom of this file and tell the user you are working from a potentially outdated summary.

When to invoke

Inputs needed

Ask the user for:

  1. Form purpose — create, edit, or both
  2. Resource name — e.g., User, Product. Used for component naming
  3. Fields — list of field names with their Zod types (e.g., name: string min 1, email: string email)
  4. Mutation hook — which React Query mutation will the form call (e.g., useCreateUser, useUpdateUser)
  5. Locationsrc/features/<feature>/components/

What to read first

Read existing form components and schemas in the user's project:

src/features/examples/components/UserForm.tsx       # create form
src/features/examples/components/UserEditForm.tsx   # edit form with pre-populated values
src/shared/utils/validators.ts                       # shared Zod schemas
src/features/examples/hooks/useCreateUser.ts         # mutation hook pattern

Check if there's already a shared schema in src/shared/utils/validators.ts for this resource. If yes, reuse it via .omit() / .pick() / .extend() rather than duplicating.

How to scaffold

Derive the schema and the form component from the pattern and implementation code in the recipe you fetched in Step 0, adapted to the user's resource and fields:

After generating

Tell the user:

  1. The file path created
  2. Whether they need to add the schema to src/shared/utils/validators.ts
  3. Whether the mutation hook (useCreate<Resource>, useUpdate<Resource>) exists — if not, suggest using reactprinciples-query skill
  4. Import path: import { <Resource>Form } from "@/features/<feature>/components/<Resource>Form"

Adapt to the existing repo

Match the conventions already in this project. Where the project's form style differs from the cookbook pattern, follow the project and note the difference once — do not force the cookbook approach.

Non-negotiable (correctness, not taste): Zod schema is source of truth, error messages live in schema not JSX, zodResolver from @hookform/resolvers/zod.

What you should NOT do

Fallback summary (only if Step 0 fails)

⚠️ Working from offline summary — live recipe may be more current.

Reference

See Form Validation with Zod recipe and existing forms in src/features/examples/components/.