zod-form-validation
БесплатноБез исполняемых скриптовНе проверенZod schema validation and React Hook Form integration for TypeScript frontends. This skill should be used when creating forms, defining API schemas…
Об этом скилле
Zod Form Validation Skill
Implements type-safe form validation using Zod schemas with React Hook Form integration in the DTX frontend.
Quick Reference
Form Setup Pattern
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from '~/components/ui/form';
// 1. Define schema
const MySchema = z.object({
email: z.string().email('Invalid email'),
name: z.string().min(2, 'Name too short'),
});
// 2. Create form with zodResolver
const form = useForm<z.infer<typeof MySchema>>({
resolver: zodResolver(MySchema),
defaultValues: { email: '', name: '' },
});
// 3. Handle submission
const onSubmit = (data: z.infer<typeof MySchema>) => {
toast.promise(apiCall(data), {
loading: 'Saving...',
success: 'Saved!',
error: (err) => `Failed: ${err?.response?.data ?? String(err)}`,
});
};
Form Field Pattern
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
Project Conventions
Schema Location
Define schemas in ~/components/<feature>/schemas.ts:
UserSchemain~/components/user/schemas.tsTeamSchemain~/components/team/schemas.tsGameSchemain~/components/game/schemas.ts
Type Extraction
Always use z.infer<typeof Schema> for types instead of manual interfaces:
export const UserSchema = z.object({ /* ... */ });
export type UserType = z.infer<typeof UserSchema>;
Error Handling
Wrap mutations in toast.promise():
import { toast } from 'sonner';
import { getLogger } from '~/lib/logger';
const log = getLogger('FormComponent');
toast.promise(apiCall(data), {
loading: 'Processing...',
success: (response) => {
setData(response);
return 'Success!';
},
error: (err) => {
log.error('API call failed', err);
return `Failed: ${err?.response?.data ?? String(err)}`;
},
});
Detailed References
For comprehensive documentation:
- Zod Schema Patterns - Schema types, validation, composition
- React Hook Form Integration - Form setup, field types, error handling
- Form Field Components - Input, Select, Checkbox patterns
Migration Guide
When migrating legacy forms from manual useState to React Hook Form + Zod:
- Create/update schema in
schemas.ts - Replace
useStatewithuseForm({ resolver: zodResolver(Schema) }) - Replace input handlers with
<FormField>components - Remove manual error state management
- Wrap form in
<Form {...form}>provider
Reference implementation: ~/pages/profile/profile.tsx
Common Patterns
Nested Objects
const Schema = z.object({
user: z.object({
name: z.string(),
email: z.string().email(),
}),
});
<FormField control={form.control} name="user.name" ... />
Optional & Nullable
const Schema = z.object({
nickname: z.string().nullable().optional(),
mmr: z.number().min(0).nullable().optional(), // illustrative only
});
The real user edit form has no single mmr field: org MMR is per game
(game_mmrs, one field per GAME_TYPES entry, built in
frontend/app/components/user/userCard/editUserSchema.ts).
Select Fields (Number Values)
<FormField
control={form.control}
name="position"
render={({ field }) => (
<Select onValueChange={(v) => field.onChange(Number(v))} defaultValue={field.value?.toString()}>
{/* options */}
</Select>
)}
/>
Dependencies
Required packages (already installed in DTX frontend):
zod: ^4.1.5react-hook-form: ^7.62.0@hookform/resolvers: ^5.2.1
Установить zod-form-validation в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл zod-form-validation?
Zod schema validation and React Hook Form integration for TypeScript frontends. This skill should be used when creating forms, defining API schemas, validating form data, implementing type-safe validation, using ZodResolver with React Hook Form, or migrating legacy forms to the Zod + React Hook Form pattern.
Как установить скилл zod-form-validation?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл zod-form-validation запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic