Implement web accessibility (a11y) best practices following WCAG guidelines to create inclusive, accessible user interfaces.
中文简介正在准备中。当前显示原文说明。
TanStack Form best practices for type-safe form management, validation, field composition, and submission handling in React. Use when building forms with complex validation, integrating schema libraries (Zod/Valibot/ArkType), composing reusable form components, managing array/dynamic fields, or integrating with meta-frameworks (TanStack Start, Next.js, Remix).
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
Version: @tanstack/react-form@latest Requires: React 18.0+, TypeScript 5.0+
npm install @tanstack/react-form
import { useForm } from '@tanstack/react-form'
function App() {
const form = useForm({
defaultValues: {
firstName: '',
lastName: '',
},
onSubmit: async ({ value }) => {
console.log(value)
},
})
return (
<form
onSubmit={(e) => {
e.preventDefault()
e.stopPropagation()
form.handleSubmit()
}}
>
<form.Field
name="firstName"
validators={{
onChange: ({ value }) =>
!value ? 'Required' : value.length < 3 ? 'Too short' : undefined,
}}
children={(field) => (
<>
<input
value={field.state.value}
onBlur={field.handleBlur}
onChange={(e) => field.handleChange(e.target.value)}
/>
{!field.state.meta.isValid && (
<em>{field.state.meta.errors.join(', ')}</em>
)}
</>
)}
/>
<form.Subscribe
selector={(state) => [state.canSubmit, state.isSubmitting]}
children={([canSubmit, isSubmitting]) => (
<button type="submit" disabled={!canSubmit}>
{isSubmitting ? '...' : 'Submit'}
</button>
)}
/>
</form>
)
}
For production apps, use createFormHook to pre-bind reusable UI components and reduce boilerplate:
import { createFormHookContexts, createFormHook } from '@tanstack/react-form'
import { TextField, NumberField, SubmitButton } from '~/ui-library'
const { fieldContext, formContext } = createFormHookContexts()
export const { useAppForm } = createFormHook({
fieldComponents: { TextField, NumberField },
formComponents: { SubmitButton },
fieldContext,
formContext,
})
npm install -D @tanstack/react-devtools @tanstack/react-form-devtools
import { TanStackDevtools } from '@tanstack/react-devtools'
import { formDevtoolsPlugin } from '@tanstack/react-form-devtools'
<TanStackDevtools
config={{ hideUntilHover: true }}
plugins={[formDevtoolsPlugin()]}
/>
| Priority | Category | Rule File | Impact |
|---|---|---|---|
| CRITICAL | Form Setup | rules/form-setup.md | Correct form creation and type inference |
| CRITICAL | Validation | rules/val-validation.md | Prevents invalid submissions and poor UX |
| CRITICAL | Schema Validation | rules/val-schema-validation.md | Type-safe validation with Zod/Valibot/ArkType |
| HIGH | Form Composition | rules/comp-form-composition.md | Reduces boilerplate, enables reusable components |
| HIGH | Field State | rules/field-state.md | Correct state access and reactivity |
| HIGH | Array Fields | rules/arr-array-fields.md | Dynamic list management |
| HIGH | Linked Fields | rules/link-linked-fields.md | Cross-field validation (e.g. confirm password) |
| MEDIUM | Listeners | rules/listen-listeners.md | Side effects on field events |
| MEDIUM | Submission | rules/sub-submission.md | Correct submit handling and meta passing |
| MEDIUM | SSR / Meta-Frameworks | rules/ssr-meta-frameworks.md | Server validation with Start/Next.js/Remix |
| LOW | UI Libraries | rules/ui-libraries.md | Headless integration with component libraries |
useForm<T>(), let TS infer from defaultValuese.preventDefault(); e.stopPropagation(); form.handleSubmit()children render prop — form.Field uses render props via children={(field) => ...}form.Subscribe with selector — subscribe to specific state slices to avoid re-rendersuseStore with selector — useStore(form.store, (s) => s.values.name) not useStore(form.store)createFormHook in production — pre-bind components for consistency and less boilerplateonChangeAsyncDebounceMs or asyncDebounceMsuseForm<MyType>() breaks the design; use typed defaultValues insteade.preventDefault() — native form submission will bypass TanStack Form's handlinguseField for reactivity — use useStore(form.store) or form.Subscribe insteaduseStore — causes full re-render on every state changetype="reset" without e.preventDefault() — native reset bypasses TanStack Form; use form.reset() explicitlyonSubmit — Standard Schema transforms aren't applied; parse manually in onSubmit// Schema validation (form-level with Zod)
const form = useForm({
defaultValues: { age: 0, name: '' },
validators: {
onChange: z.object({ age: z.number().min(13), name: z.string().min(1) }),
},
onSubmit: ({ value }) => console.log(value),
})
// Array fields
<form.Field name="hobbies" mode="array" children={(field) => (
<div>
{field.state.value.map((_, i) => (
<form.Field key={i} name={`hobbies[${i}].name`} children={(sub) => (
<input value={sub.state.value} onChange={(e) => sub.handleChange(e.target.value)} />
)} />
))}
<button type="button" onClick={() => field.pushValue({ name: '' })}>Add</button>
</div>
)} />
// Linked fields (confirm password)
<form.Field name="confirm_password" validators={{
onChangeListenTo: ['password'],
onChange: ({ value, fieldApi }) =>
value !== fieldApi.form.getFieldValue('password') ? 'Passwords do not match' : undefined,
}} children={(field) => <input value={field.state.value} onChange={(e) => field.handleChange(e.target.value)} />} />
// Listeners (reset province when country changes)
<form.Field name="country" listeners={{
onChange: ({ value }) => { form.setFieldValue('province', '') },
}} children={(field) => <input value={field.state.value} onChange={(e) => field.handleChange(e.target.value)} />} />
// Form composition with withForm
const ChildForm = withForm({
defaultValues: { firstName: '', lastName: '' },
render: function Render({ form }) {
return <form.AppField name="firstName" children={(field) => <field.TextField label="First Name" />} />
},
})
还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Implement web accessibility (a11y) best practices following WCAG guidelines to create inclusive, accessible user interfaces.
中文简介正在准备中。当前显示原文说明。
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.
中文简介正在准备中。当前显示原文说明。
Bun runtime, package manager, bundler, and test runner. Use when running scripts with bun, managing packages, serving HTTP with Bun.serve, querying databases with Bun.sql/bun:sqlite/Bun.redis, shell scripting with $, using S3/file I/O, writing tests with bun:test, bundling or compiling to executable, or using any Bun-specific API (spawn, glob, semver, FFI, workers, plugins, HTMLRewriter).
中文简介正在准备中。当前显示原文说明。
Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.
中文简介正在准备中。当前显示原文说明。
Manage SVG icons as framework components using Denji CLI. Use when the user needs to add, remove, list, or manage SVG icons in React, Preact, Solid, Qwik, Vue, or Svelte projects. Triggers include requests to "add an icon", "set up icons", "manage SVG icons", "remove an icon", "list icons", or any task involving Iconify icons as framework components.
中文简介正在准备中。当前显示原文说明。
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
中文简介正在准备中。当前显示原文说明。