react-forms
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTanStack Form v1 Core Features
TanStack Form v1 核心特性
Agent Workflow (MANDATORY)
Agent 工作流(强制要求)
Before ANY implementation, use to spawn 3 agents:
TeamCreate- fuse-ai-pilot:explore-codebase - Analyze existing form components and validation patterns
- fuse-ai-pilot:research-expert - Verify latest TanStack Form v1 docs via Context7/Exa
- mcp__context7__query-docs - Check Zod validation and React 19 Server Actions patterns
After implementation, run fuse-ai-pilot:sniper for validation.
在进行任何实现之前,使用生成3个Agent:
TeamCreate- fuse-ai-pilot:explore-codebase - 分析现有表单组件和验证模式
- fuse-ai-pilot:research-expert - 通过Context7/Exa验证最新TanStack Form v1文档
- mcp__context7__query-docs - 检查Zod验证和React 19 Server Actions模式
实现完成后,运行fuse-ai-pilot:sniper进行验证。
MANDATORY: SOLID Principles
强制要求:SOLID原则
ALWAYS apply SOLID principles from skill.
solid-react→ See for complete rules
../solid-react/SKILL.mdKey Rules:
- Files < 100 lines (split at 90)
- Interfaces in
modules/[feature]/src/interfaces/ - JSDoc mandatory on all exports
- No business logic in components
始终遵循技能中的SOLID原则。
solid-react→ 完整规则请查看
../solid-react/SKILL.md核心规则:
- 文件行数<100行(90行时拆分)
- 接口放在目录下
modules/[feature]/src/interfaces/ - 所有导出内容必须添加JSDoc注释
- 组件中不得包含业务逻辑
Core Hooks
核心Hook
| Hook | Purpose | Guide |
|---|---|---|
| Initialize form with validation | |
| Subscribe to individual field | |
| Render prop component for fields | |
| Watch form state changes | |
→ See for detailed usage
references/tanstack-form-basics.md| Hook | 用途 | 参考文档 |
|---|---|---|
| 初始化带验证的表单 | |
| 订阅单个字段 | |
| 用于字段的渲染属性组件 | |
| 监听表单状态变化 | |
→ 详细用法请查看
references/tanstack-form-basics.mdValidation Adapters
验证适配器
| Library | Adapter | Bundle Size |
|---|---|---|
| Zod | | ~12KB |
| Yup | | ~40KB |
| Valibot | | ~6KB |
→ See for Zod patterns
→ See for alternatives
references/zod-validation.mdreferences/yup-valibot.md| 库 | 适配器 | 包大小 |
|---|---|---|
| Zod | | ~12KB |
| Yup | | ~40KB |
| Valibot | | ~6KB |
→ Zod模式请查看
→ 替代方案请查看
references/zod-validation.mdreferences/yup-valibot.mdKey Features
核心特性
Async Validation
异步验证
Server-side checks with debouncing and loading states.
→ See
references/async-validation.md带防抖和加载状态的服务器端检查。
→ 请查看
references/async-validation.mdServer Actions (React 19)
React 19 Server Actions
Integration with useActionState and progressive enhancement.
→ See
references/server-actions.md与useActionState和渐进式增强集成。
→ 请查看
references/server-actions.mdArrays & Nested Fields
数组与嵌套字段
Dynamic field arrays and dot notation for nested objects.
→ See
references/arrays-nested.md动态字段数组和用于嵌套对象的点表示法。
→ 请查看
references/arrays-nested.mdTypeScript Integration
TypeScript集成
Full type inference from Zod schemas and defaultValues.
→ See
references/typescript.md从Zod schema和defaultValues自动推断类型。
→ 请查看
references/typescript.mdshadcn/ui Integration
shadcn/ui集成
Field wrapper components with shadcn styling.
→ See
references/shadcn-integration.md带shadcn样式的字段包装组件。
→ 请查看
references/shadcn-integration.mdListeners (Side Effects)
监听器(副作用)
onMount, onChange, onBlur, onSubmit with debouncing.
→ See
references/listeners.md带防抖的onMount、onChange、onBlur、onSubmit。
→ 请查看
references/listeners.mdLinked Fields
关联字段
Cross-field validation and dependent dropdowns.
→ See
references/linked-fields.md跨字段验证和依赖下拉框。
→ 请查看
references/linked-fields.mdReactivity & Performance
响应式与性能
useStore selectors and granular subscriptions.
→ See
references/reactivity.mduseStore选择器和细粒度订阅。
→ 请查看
references/reactivity.mdReset API
重置API
Form and field reset with custom values.
→ See
references/reset-api.md带自定义值的表单和字段重置。
→ 请查看
references/reset-api.mdSSR & Hydration
SSR与Hydration
TanStack Start integration and server state merge.
→ See
references/ssr-hydration.mdTanStack Start集成和服务器状态合并。
→ 请查看
references/ssr-hydration.mdDevtools
开发者工具
Debug form state with @tanstack/react-form-devtools.
→ See
references/devtools.md使用@tanstack/react-form-devtools调试表单状态。
→ 请查看
references/devtools.mdReact Native
React Native
Mobile-specific patterns with TextInput.
→ See
references/react-native.md针对TextInput的移动端特定模式。
→ 请查看
references/react-native.mdStandard Schema
标准Schema
ArkType and Effect Schema support.
→ See
references/standard-schema.md支持ArkType和Effect Schema。
→ 请查看
references/standard-schema.mdTemplates
模板
| Template | Use Case |
|---|---|
| Login/signup with Zod |
| Wizard with step validation |
| Add/remove field arrays |
| File input with preview |
| React 19 Server Actions |
| useOptimistic integration |
| Dot notation nested fields |
| Debounced search |
| Show/hide based on values |
| Reusable field components |
| Side effects & auto-save |
| Cross-field validation |
| Performance optimization |
| Form/field reset patterns |
| SSR & hydration |
| Devtools integration |
| React Native forms |
| 模板 | 适用场景 |
|---|---|
| 基于Zod的登录/注册表单 |
| 带步骤验证的向导表单 |
| 可添加/删除的字段数组 |
| 带预览的文件输入表单 |
| React 19 Server Actions表单 |
| useOptimistic集成表单 |
| 点表示法嵌套字段表单 |
| 防抖搜索表单 |
| 根据值显示/隐藏字段的表单 |
| 可复用字段组件表单 |
| 副作用与自动保存表单 |
| 跨字段验证表单 |
| 性能优化表单 |
| 表单/字段重置模式 |
| SSR与Hydration表单 |
| 开发者工具集成表单 |
| React Native表单 |
Best Practices
最佳实践
- Validation: Use Zod/Yup/Valibot, NOT custom regex
- Async: Debounce server validation (300-500ms)
- Errors: Display
field.state.meta.errors - Nested: Use dot notation ()
address.street - Arrays: Use with pushValue/removeValue
mode="array" - TypeScript: Infer types with
z.infer<typeof schema>
- 验证:使用Zod/Yup/Valibot,不要使用自定义正则
- 异步:对服务器验证添加防抖(300-500ms)
- 错误提示:显示
field.state.meta.errors - 嵌套字段:使用点表示法(如)
address.street - 数组:使用配合pushValue/removeValue
mode="array" - TypeScript:通过推断类型
z.infer<typeof schema>
Forbidden (Anti-Patterns)
禁用项(反模式)
- ❌ for form state → use
useStateuseForm() - ❌ Regex validation → use Zod/Yup/Valibot
- ❌ No debounce on async → use
onChangeAsyncDebounceMs - ❌ Validation in components → move to schema
- ❌ Direct → use
onChangefield.handleChange - ❌ No TypeScript types → use
z.infer<typeof schema>
- ❌ 使用管理表单状态 → 请使用
useStateuseForm() - ❌ 使用正则验证 → 请使用Zod/Yup/Valibot
- ❌ 异步验证不防抖 → 请使用
onChangeAsyncDebounceMs - ❌ 在组件中进行验证 → 移至schema中
- ❌ 直接使用→ 请使用
onChangefield.handleChange - ❌ 不添加TypeScript类型 → 请使用
z.infer<typeof schema>