一键导入
react-native-forms-validation
Best practices for implementing forms with React Hook Form and Zod.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Best practices for implementing forms with React Hook Form and Zod.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Mandatory rules and components for handling keyboard avoidance smoothly in the React Native app.
How to correctly handle and format protobuf Timestamp dates sent by the API Gateway to prevent "Invalid Date" issues.
Senior-level React Native architecture and patterns for Expo 54 apps.
Strict coding standards, naming conventions, file size limits, and typing rules.
Guidelines for managing server state, queries, and API clients in React Native.
Mandatory rule to never use deprecated APIs or ignore deprecation warnings.
| name | React Native Forms & Validation |
| description | Best practices for implementing forms with React Hook Form and Zod. |
We use React Hook Form (RHF) and Zod to manage all form state and validation.
react-hook-form@hookform/resolvers/zodzodAlways start by defining a strict Zod schema for your form data. This provides both runtime validation and static TypeScript types.
import { z } from 'zod';
export const loginSchema = z.object({
email: z.string().email('Adresse email invalide'),
password: z.string().min(8, 'Le mot de passe doit contenir 8 caractères minimum'),
});
export type LoginFormData = z.infer<typeof loginSchema>;
Use the zodResolver to connect your schema to RHF.
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
const {
control,
handleSubmit,
formState: { errors },
} = useForm<LoginFormData>({
resolver: zodResolver(loginSchema),
defaultValues: { email: '', password: '' },
});
Because React Native does not use native HTML <form> tags, you must wrap all inputs in RHF's <Controller> component.
import { Controller } from 'react-hook-form';
<Controller
control={control}
name="email"
render={({ field: { onChange, onBlur, value } }) => (
<AppTextInput
onBlur={onBlur}
onChangeText={onChange}
value={value}
error={errors.email?.message}
/>
)}
/>;
[!WARNING] Do not use local
useStatefor form fields. Let React Hook Form manage the entire state to prevent unnecessary re-renders.