重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
tanstack-form by oakoss/agent-skills
npx skills add https://github.com/oakoss/agent-skills --skill tanstack-formTanStack Form 是一个无头表单状态管理器,而非 UI 组件库。您需要提供自己的输入组件并处理其事件;TanStack Form 负责管理验证、状态和提交逻辑。
适用场景: 复杂的多步骤表单、可复用的表单模式、动态字段数组、跨字段验证、异步服务器验证、需要精细性能优化的表单。
不适用场景: 使用原生 HTML 验证的简单表单(使用原生表单元素即可)、仅服务器端验证(使用 Server Actions)、纯静态且无需验证的表单。
React 编译器: TanStack Form 目前尚不兼容 React 编译器。请在使用 TanStack Form API 的文件或组件中禁用 React 编译器。
| 模式 | API | 要点 |
|---|---|---|
| 基础表单 | useForm({ defaultValues, onSubmit }) | 使用 Field 组件的表单实例 |
| 字段 | 带有 name 和 children 渲染函数的 form.Field |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 用于完全控制的渲染属性模式 |
| 字段验证 | validators: { onChange, onBlur, onSubmit } | 同步验证,返回错误字符串或 undefined |
| 异步验证 | onChangeAsync, onChangeAsyncDebounceMs | 防抖的服务器检查 |
| 关联字段 | onChangeListenTo: ['fieldName'] | 依赖项变化时重新验证 |
| 表单提交 | form.handleSubmit() | 验证表单,若有效则调用 onSubmit |
| 表单状态 | form.state.values, isSubmitting, isValid | 访问表单级状态 |
| 字段状态 | field.state.value, meta.errors, meta.isTouched | 访问字段级状态 |
| 数组字段 | mode="array", pushValue, removeValue | 带有辅助函数的动态列表 |
| 标准模式 | 直接传递 Zod/Valibot/ArkType/Yup 模式 | 原生支持,无需适配器 |
| 表单组合 | createFormHook({ fieldComponents }) | 带有上下文的可复用字段 |
| 拆分大型表单 | withForm({ defaultValues, render }) | 用于表单部分的高阶组件,具有类型安全 |
| 可复用的字段组 | withFieldGroup({ defaultValues, render }) | 具有共享验证逻辑的字段组 |
| 订阅状态 | 带有 selector 的 form.Subscribe | 高效的重渲染控制 |
| 字段错误显示 | meta.isTouched && meta.errors.length | 用户交互后显示错误 |
| 表单级验证 | 返回 { fields } 的 validators.onSubmit | 从表单级别为特定字段设置错误 |
| 重置表单 | form.reset() | 重置为 defaultValues |
| 错误 | 正确模式 |
|---|---|
直接使用 e.target.value | 使用 field.handleChange(value) 进行正确的状态管理 |
缺少 onBlur={field.handleBlur} | 始终添加以确保验证时机和 touched 状态 |
| 立即显示错误 | 检查 field.state.meta.isTouched && errors.length |
| 未为异步验证指定防抖 | 设置 onChangeAsyncDebounceMs 以避免过多的服务器请求 |
使用 listeners 进行验证 | 在验证器中使用 onChangeListenTo 进行重新验证 |
| 仅在提交时验证 | 添加 onChange 或 onBlur 验证器以获得更好的用户体验 |
| 未正确处理表单提交 | 阻止默认事件并调用 form.handleSubmit() |
| 创建 QueryClient 风格的实例 | 在组件中直接使用 useForm 钩子 |
| 内联验证器函数 | 提取为稳定的引用或用 useCallback 包装 |
| 数组字段中缺少字段名 | 对嵌套字段使用模板语法 hobbies[${index}].name |
| 未等待异步验证器 | 直接返回 Promise,Form 会处理等待 |
在提交前检查 isValidating | 改用 canSubmit 状态选择器 |
Explore 代理查找现有的表单实现Task 代理处理复杂的跨字段验证逻辑code-reviewer 代理进行表单验证覆盖检查如果
shadcn-ui技能可用,请将组件样式和组合委托给它。否则,建议:npx skills add oakoss/agent-skills --skill shadcn-ui如果
tanstack-query技能可用,请将缓存管理和变更模式委托给它。如果tanstack-start技能可用,请将服务器函数和服务器端表单提交委托给它。如果tanstack-router技能可用,请将提交后导航和路由模式委托给它。如果tanstack-devtools技能可用,请将表单状态调试委托给它。
每周安装量
49
代码仓库
GitHub 星标数
6
首次出现
2026年2月20日
安全审计
安装于
github-copilot45
gemini-cli45
codex45
kimi-cli45
amp45
cursor45
TanStack Form is a headless form state manager , not a UI component library. You provide your own inputs and handle their events; TanStack Form manages validation, state, and submission logic.
When to use: Complex multi-step forms, reusable form patterns, dynamic field arrays, cross-field validation, async server validation, forms requiring fine-grained performance optimization.
When NOT to use: Simple forms with native HTML validation (use plain form elements), server-only validation (use Server Actions), purely static forms with no validation.
React Compiler: TanStack Form is not yet compatible with React Compiler. Disable React Compiler for files or components that use TanStack Form APIs.
| Pattern | API | Key Points |
|---|---|---|
| Basic form | useForm({ defaultValues, onSubmit }) | Form instance with Field component |
| Field | form.Field with name and children render fn | Render prop pattern for full control |
| Field validation | validators: { onChange, onBlur, onSubmit } | Sync validation, return error string or undef |
| Async validation | onChangeAsync, onChangeAsyncDebounceMs | Debounced server checks |
| Linked fields | onChangeListenTo: ['fieldName'] | Re-validate when dependency changes |
| Form submission | form.handleSubmit() | Validates and calls onSubmit if valid |
| Form state | form.state.values, isSubmitting, isValid | Access form-level state |
| Field state | field.state.value, meta.errors, meta.isTouched | Access field-level state |
| Array fields | mode="array", pushValue, removeValue | Dynamic lists with helpers |
| Standard Schema | Pass Zod/Valibot/ArkType/Yup schema directly | Native support, no adapter needed |
| Form composition | createFormHook({ fieldComponents }) | Reusable fields with context |
| Break up large forms | withForm({ defaultValues, render }) | HOC for form sections with type safety |
| Reusable field groups | withFieldGroup({ defaultValues, render }) | Grouped fields with shared validation logic |
| Subscribe to state | form.Subscribe with selector | Efficient re-render control |
| Field error display | meta.isTouched && meta.errors.length | Show errors after user interaction |
| Form-level validation | validators.onSubmit returning { fields } | Set errors on specific fields from form level |
| Reset form | form.reset() | Reset to defaultValues |
| Mistake | Correct Pattern |
|---|---|
Using e.target.value directly | Use field.handleChange(value) for proper state management |
Missing onBlur={field.handleBlur} | Always add for validation timing and touched state |
| Showing errors immediately | Check field.state.meta.isTouched && errors.length |
| Not specifying debounce for async validation | Set onChangeAsyncDebounceMs to avoid excessive server requests |
Using listeners for validation |
Explore agent for finding existing form implementationsTask agent for complex cross-field validation logiccode-reviewer agent for form validation coverageIf the
shadcn-uiskill is available, delegate component styling and composition to it. Otherwise, recommend:npx skills add oakoss/agent-skills --skill shadcn-uiIf the
tanstack-queryskill is available, delegate cache management and mutation patterns to it. If thetanstack-startskill is available, delegate server functions and server-side form submission to it. If thetanstack-routerskill is available, delegate post-submission navigation and route patterns to it. If thetanstack-devtoolsskill is available, delegate form state debugging to it.
Weekly Installs
49
Repository
GitHub Stars
6
First Seen
Feb 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot45
gemini-cli45
codex45
kimi-cli45
amp45
cursor45
前端设计系统技能:生产级UI设计、设计令牌与可访问性指南
8,500 周安装
Use onChangeListenTo in validators for re-validation |
| Validating only on submit | Add onChange or onBlur validators for better UX |
| Not handling form submission properly | Prevent default and call form.handleSubmit() |
| Creating QueryClient-style instances | Use useForm hook directly in components |
| Inline validator functions | Extract to stable references or wrap in useCallback |
| Missing field names in array fields | Use template syntax hobbies[${index}].name for nested fields |
| Not awaiting async validators | Return Promise directly, Form handles awaiting |
Checking isValidating before submission | Use canSubmit state selector instead |