form-patterns
БесплатноБез исполняемых скриптовНе проверенForm handling with React Hook Form and Zod validation
Об этом скилле
Form Patterns
1. Basic Form with Validation
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
const loginSchema = z.object({
email: z.string().email("Invalid email address"),
password: z.string().min(8, "Password must be at least 8 characters"),
});
type LoginFormData = z.infer<typeof loginSchema>;
export function LoginForm() {
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<LoginFormData>({
resolver: zodResolver(loginSchema),
});
const onSubmit = async (data: LoginFormData) => {
await login(data);
};
return (
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div>
<label htmlFor="email" className="block text-sm font-medium">
Email
</label>
<input
{...register("email")}
type="email"
id="email"
className="mt-1 block w-full rounded-md border px-3 py-2"
/>
{errors.email && (
<p className="mt-1 text-sm text-red-600">{errors.email.message}</p>
)}
</div>
<div>
<label htmlFor="password" className="block text-sm font-medium">
Password
</label>
<input
{...register("password")}
type="password"
id="password"
className="mt-1 block w-full rounded-md border px-3 py-2"
/>
{errors.password && (
<p className="mt-1 text-sm text-red-600">{errors.password.message}</p>
)}
</div>
<button
type="submit"
disabled={isSubmitting}
className="w-full rounded-md bg-primary px-4 py-2 text-white disabled:opacity-50"
>
{isSubmitting ? "Signing in..." : "Sign in"}
</button>
</form>
);
}
2. Complex Schema Validation
const userSchema = z.object({
name: z.string().min(2, "Name is too short"),
email: z.string().email(),
age: z.number().min(18, "Must be 18 or older").max(120),
// Optional with default
newsletter: z.boolean().default(false),
// Enum
role: z.enum(["user", "admin", "moderator"]),
// Nested object
address: z.object({
street: z.string().min(1),
city: z.string().min(1),
zip: z.string().regex(/^\d{5}$/, "Invalid ZIP code"),
}),
// Array
tags: z.array(z.string()).min(1, "Add at least one tag"),
// Conditional validation
password: z.string().min(8),
confirmPassword: z.string(),
}).refine((data) => data.password === data.confirmPassword, {
message: "Passwords don't match",
path: ["confirmPassword"],
});
3. Reusable Form Field Component
import { useFormContext, FieldPath, FieldValues } from "react-hook-form";
interface FormFieldProps<T extends FieldValues> {
name: FieldPath<T>;
label: string;
type?: "text" | "email" | "password" | "number";
placeholder?: string;
}
export function FormField<T extends FieldValues>({
name,
label,
type = "text",
placeholder,
}: FormFieldProps<T>) {
const {
register,
formState: { errors },
} = useFormContext<T>();
const error = errors[name];
return (
<div className="space-y-1">
<label htmlFor={name} className="block text-sm font-medium">
{label}
</label>
<input
{...register(name)}
type={type}
id={name}
placeholder={placeholder}
className={cn(
"block w-full rounded-md border px-3 py-2",
error && "border-red-500 focus:ring-red-500"
)}
/>
{error && (
<p className="text-sm text-red-600">
{error.message as string}
</p>
)}
</div>
);
}
// Usage with FormProvider
function MyForm() {
const methods = useForm<FormData>({ resolver: zodResolver(schema) });
return (
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)}>
<FormField name="email" label="Email" type="email" />
<FormField name="password" label="Password" type="password" />
</form>
</FormProvider>
);
}
4. Dynamic Form Fields (Array)
import { useFieldArray, useForm } from "react-hook-form";
const schema = z.object({
users: z.array(z.object({
name: z.string().min(1),
email: z.string().email(),
})).min(1),
});
type FormData = z.infer<typeof schema>;
function DynamicForm() {
const { control, register, handleSubmit } = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
users: [{ name: "", email: "" }],
},
});
const { fields, append, remove } = useFieldArray({
control,
name: "users",
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
{fields.map((field, index) => (
<div key={field.id} className="flex gap-4">
<input {...register(`users.${index}.name`)} placeholder="Name" />
<input {...register(`users.${index}.email`)} placeholder="Email" />
<bu
Установить form-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл form-patterns?
Form handling with React Hook Form and Zod validation
Как установить скилл form-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл form-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic