본문으로 건너뛰기
cccskills
무료GitHub에 공개

tanstack-form

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).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(12)

  • SKILL.md6.8 KB
  • rules/arr-array-fields.md3.4 KB
  • rules/comp-form-composition.md4.0 KB
  • rules/field-state.md2.5 KB
  • rules/form-setup.md2.6 KB
  • rules/link-linked-fields.md2.4 KB
  • rules/listen-listeners.md2.2 KB
  • rules/ssr-meta-frameworks.md4.5 KB
  • rules/sub-submission.md2.2 KB
  • rules/ui-libraries.md3.0 KB
  • rules/val-schema-validation.md2.5 KB
  • rules/val-validation.md3.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

TanStack Form

Version: @tanstack/react-form@latest Requires: React 18.0+, TypeScript 5.0+

Quick Setup

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>
  )
}

Production Setup (Recommended)

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,
})

Devtools

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()]}
/>

Rule Categories

PriorityCategoryRule FileImpact
CRITICALForm Setuprules/form-setup.mdCorrect form creation and type inference
CRITICALValidationrules/val-validation.mdPrevents invalid submissions and poor UX
CRITICALSchema Validationrules/val-schema-validation.mdType-safe validation with Zod/Valibot/ArkType
HIGHForm Compositionrules/comp-form-composition.mdReduces boilerplate, enables reusable components
HIGHField Staterules/field-state.mdCorrect state access and reactivity
HIGHArray Fieldsrules/arr-array-fields.mdDynamic list management
HIGHLinked Fieldsrules/link-linked-fields.mdCross-field validation (e.g. confirm password)
MEDIUMListenersrules/listen-listeners.mdSide effects on field events
MEDIUMSubmissionrules/sub-submission.mdCorrect submit handling and meta passing
MEDIUMSSR / Meta-Frameworksrules/ssr-meta-frameworks.mdServer validation with Start/Next.js/Remix
LOWUI Librariesrules/ui-libraries.mdHeadless integration with component libraries

Critical Rules

Always Do

  • Type from defaultValues — never pass generics to useForm<T>(), let TS infer from defaultValues
  • Prevent default on submit — e.preventDefault(); e.stopPropagation(); form.handleSubmit()
  • Use children render prop — form.Field uses render props via children={(field) => ...}
  • Use form.Subscribe with selector — subscribe to specific state slices to avoid re-renders
  • Use useStore with selector — useStore(form.store, (s) => s.values.name) not useStore(form.store)
  • Use createFormHook in production — pre-bind components for consistency and less boilerplate
  • Debounce async validators — set onChangeAsyncDebounceMs or asyncDebounceMs

Never Do

  • Pass generics — useForm<MyType>() breaks the design; use typed defaultValues instead
  • Skip e.preventDefault() — native form submission will bypass TanStack Form's handling
  • Use useField for reactivity — use useStore(form.store) or form.Subscribe instead
  • Omit selector in useStore — causes full re-render on every state change
  • Use type="reset" without e.preventDefault() — native reset bypasses TanStack Form; use form.reset() explicitly
  • Expect transformed values in onSubmit — Standard Schema transforms aren't applied; parse manually in onSubmit

Key Patterns

// 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" />} />
  },
})

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Implement web accessibility (a11y) best practices following WCAG guidelines to create inclusive, accessible user interfaces.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

fellipeutaka/kanpeki332026년 8월 28일 업데이트

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

fellipeutaka/kanpeki332026년 8월 28일 업데이트

bun

무료

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).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

fellipeutaka/kanpeki332026년 8월 28일 업데이트

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

fellipeutaka/kanpeki332026년 8월 28일 업데이트

denji

무료

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

fellipeutaka/kanpeki332026년 8월 28일 업데이트

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

fellipeutaka/kanpeki332026년 8월 28일 업데이트

fellipeutaka의 스킬 모두 보기

이 스킬의 문제 신고