web-forms-tanstack-form
TanStack Formというライブラリを活用し、入力フォームの作成、入力項目の管理、データの検証、配列データの扱い、項目間の連携などを型安全に行えるようにするSkill。
📜 元の英語説明(参考)
TanStack Form patterns - useForm, form.Field, validators, arrays, linked fields, createFormHook, type safety
🇯🇵 日本人クリエイター向け解説
TanStack Formというライブラリを活用し、入力フォームの作成、入力項目の管理、データの検証、配列データの扱い、項目間の連携などを型安全に行えるようにするSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o web-forms-tanstack-form.zip https://jpskill.com/download/10280.zip && unzip -o web-forms-tanstack-form.zip && rm web-forms-tanstack-form.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10280.zip -OutFile "$d\web-forms-tanstack-form.zip"; Expand-Archive "$d\web-forms-tanstack-form.zip" -DestinationPath $d -Force; ri "$d\web-forms-tanstack-form.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
web-forms-tanstack-form.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
web-forms-tanstack-formフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
TanStack Form のパターン
クイックガイド:
useFormをdefaultValuesと型付きジェネリクスと共に使用します。form.Fieldを render-prop のchildrenパターンを使ってフィールドをレンダリングします。バリデーションはフォームとフィールドレベルの両方のvalidatorsプロパティに存在します。onChange、onBlur、onSubmit(同期) とそれらのAsyncバリアントを使用します。pushValue/removeValueを持つ動的なフィールドリストにはmode="array"を使用します。クロスフィールドバリデーションにはonChangeListenToを使用します。アプリ全体の整合性のために、createFormHookを介して共有のuseAppFormを作成します。常にdefaultValuesを提供してください。TanStack Form はそれらから型を推論します。
<critical_requirements>
重要: この Skill を使用する前に
すべてのコードは CLAUDE.md のプロジェクト規約に従う必要があります (kebab-case、名前付きエクスポート、インポート順序、
import type、名前付き定数)
(useForm に defaultValues を必ず提供する必要があります — TanStack Form はそれらからフィールド型を推論します)
(children render prop を持つ form.Field を必ず使用する必要があります — TanStack Form は register や Controller を使用しません)
(バリデーションには必ず validators プロパティを使用する必要があります — インラインの rules や外部リゾルバーラッパーは使用しません)
(field.state.meta.errors を配列として処理する必要があります — 常に .map() でエラーを処理します)
(フォームの onSubmit ハンドラー内で form.handleSubmit() を e.preventDefault() と共に呼び出す必要があります)
</critical_requirements>
自動検出: TanStack Form, @tanstack/react-form, @tanstack/vue-form, @tanstack/solid-form, @tanstack/angular-form, @tanstack/lit-form, useForm from tanstack, form.Field, createFormHook, createFormHookContexts, useAppForm, fieldContext, formContext, handleSubmit tanstack, pushValue, removeValue, onChangeListenTo, field.handleChange, field.handleBlur, field.state, formDevtoolsPlugin
使用する場面:
- フィールド型が
defaultValuesから推論される型安全なフォームを構築する場合 - 同期、非同期、およびクロスフィールドルールによる複雑なバリデーションを管理する場合
- フィールドグループの追加/削除 (配列フィールド) を伴う動的なフォーム
- 複数のフレームワークプロジェクト (React, Vue, Solid, Angular, Lit)
- 既に TanStack エコシステムを使用しているプロジェクト
使用しない場面:
- バリデーションのない単一の入力 (ネイティブステートを使用)
- サーバーアクションを持つサーバー専用フォーム (ネイティブフォーム + アクションを使用)
- 読み取り専用のデータ表示 (フォームのシナリオではない)
目次
詳細なリソース:
- examples/core.md - 基本的なフォーム、Field コンポーネント、TypeScript、フォーム送信
- examples/validation.md - 同期/非同期バリデーション、バリデーターアダプター、フォームレベルのバリデーション
- examples/arrays.md - pushValue/removeValue を使用した動的な配列フィールド
- examples/composition.md - createFormHook, useAppForm, リスナー、副作用
- reference.md - API テーブル、バリデーターイベント、意思決定フレームワーク
<philosophy>
哲学
TanStack Form は 設計上、ヘッドレスで型安全 です。UI を一切所有せず、すべての入力を自分でレンダリングします。このライブラリは、フォームの状態、バリデーションのオーケストレーション、およびフィールド管理を提供します。型は defaultValues からすべてのフィールド名、値、およびエラーに流れます。手動のジェネリクスは必要ありません (ただし、提供することはできます)。
コア原則:
- デフォルトからの型推論 -
defaultValuesはフォームの形状を定義します。フィールド名と値は完全に型付けされます - ヘッドレス - UI に関する意見はゼロ。任意のコンポーネントライブラリまたはネイティブ入力で動作します
- バリデーションイベント駆動 - バリデーターは、フィールドごとまたはフォームごとに特定のイベント (
onChange、onBlur、onSubmit) にアタッチします - フレームワークに依存しないコア - React、Vue、Solid、Angular、および Lit で同じメンタルモデル
- ファクトリによる構成 -
createFormHookはアプリ全体でフィールド/フォームコンポーネントを共有します
</philosophy>
<patterns>
コアパターン
パターン 1: 基本的な useForm + form.Field
すべてのフォームは useForm で始まり、form.Field を介してフィールドをレンダリングします。children render prop は、state、handleChange、および handleBlur を持つフィールド API を受け取ります。
import { useForm } from "@tanstack/react-form";
const form = useForm({
defaultValues: { name: "", email: "" },
onSubmit: async ({ value }) => {
await submitToApi(value);
},
});
return (
<form
onSubmit={(e) => {
e.preventDefault();
form.handleSubmit();
}}
>
<form.Field
name="email"
children={(field) => (
<input
value={field.state.value}
onBlur={field.handleBlur}
onChange={(e) => field.handleChange(e.target.value)}
/>
)}
/>
</form>
);
他のフォームライブラリとの主な違い: register、Controller、ref の転送はありません。常に field.handleChange と field.state.value を明示的に使用します。
エラー表示とアクセシビリティを備えた完全なフォームについては、examples/core.md を参照してください。
パターン 2: フィールドレベルのバリデーション
バリデーターは validators プロパティの関数です。同期バリデーターは文字列 (エラー) または undefined (有効) を返します。非同期バリデーターは onChangeAsync、onBlurAsync、onSubmitAsync を使用します。
<form.Field
name="age"
validators={{
onChange: ({ value }) => (value < 13 ? "Must be 13 or older" : undefined),
onBlurAsync: async ({ value }) => {
const exists = await checkAge(value);
return exists ? undefined : "Age not valid on server";
},
}}
children={(field) => (
<div>
<input
type="number"
value={field.state.value}
onBlur={field.handleBlur}
onChange={(e) => field.handleChange(e.target.valueAsNumber)}
/>
{field.state.meta.errors.map((err) => (
<em key={err} role="alert">
{err}
</em>
))}
</div>
)}
/>
同期優先ゲーティング: onBlur と onBlurAsync の両方が存在する場合、非同期バリデーターは同期バリデーターが合格した場合にのみ実行されます。onChange/onChangeAsync も同様です。
すべてのバリデーションパターンとアダプターの統合については、examples/validation.md を参照してください。
パターン 3: リンクされたフィールド (C
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
TanStack Form Patterns
Quick Guide: Use
useFormwithdefaultValuesand typed generics. Render fields withform.Fieldusing the render-propchildrenpattern. Validation lives in thevalidatorsprop on both form and field level — useonChange,onBlur,onSubmit(sync) and theirAsyncvariants. Usemode="array"for dynamic field lists withpushValue/removeValue. UseonChangeListenTofor cross-field validation. For app-wide consistency, create a shareduseAppFormviacreateFormHook. Always providedefaultValues— TanStack Form infers types from them.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST provide defaultValues to useForm — TanStack Form infers field types from them)
(You MUST use form.Field with the children render prop — TanStack Form does not use register or Controller)
(You MUST use the validators prop for validation — NOT inline rules or external resolver wrappers)
(You MUST handle field.state.meta.errors as an array — always .map() over errors)
(You MUST call form.handleSubmit() inside the form's onSubmit handler with e.preventDefault())
</critical_requirements>
Auto-detection: TanStack Form, @tanstack/react-form, @tanstack/vue-form, @tanstack/solid-form, @tanstack/angular-form, @tanstack/lit-form, useForm from tanstack, form.Field, createFormHook, createFormHookContexts, useAppForm, fieldContext, formContext, handleSubmit tanstack, pushValue, removeValue, onChangeListenTo, field.handleChange, field.handleBlur, field.state, formDevtoolsPlugin
When to use:
- Building type-safe forms where field types are inferred from
defaultValues - Managing complex validation with sync, async, and cross-field rules
- Dynamic forms with add/remove field groups (array fields)
- Multi-framework projects (React, Vue, Solid, Angular, Lit)
- Projects already using the TanStack ecosystem
When NOT to use:
- Single input without validation (use native state)
- Server-only forms with server actions (use native form + action)
- Read-only data display (not a form scenario)
Table of Contents
Detailed Resources:
- examples/core.md - Basic form, Field component, TypeScript, form submission
- examples/validation.md - Sync/async validation, validator adapters, form-level validation
- examples/arrays.md - Dynamic array fields with pushValue/removeValue
- examples/composition.md - createFormHook, useAppForm, listeners, side effects
- reference.md - API tables, validator events, decision frameworks
<philosophy>
Philosophy
TanStack Form is headless and type-safe by design. It owns zero UI — you render every input yourself. The library provides form state, validation orchestration, and field management. Types flow from defaultValues through every field name, value, and error — no manual generics required (though you can provide them).
Core Principles:
- Type inference from defaults -
defaultValuesdefines the form shape; field names and values are fully typed - Headless - Zero UI opinions; works with any component library or native inputs
- Validation-event-driven - Validators attach to specific events (
onChange,onBlur,onSubmit) per field or per form - Framework-agnostic core - Same mental model across React, Vue, Solid, Angular, and Lit
- Composition via factory -
createFormHookshares field/form components across an app
</philosophy>
<patterns>
Core Patterns
Pattern 1: Basic useForm + form.Field
Every form starts with useForm and renders fields via form.Field. The children render prop receives the field API with state, handleChange, and handleBlur.
import { useForm } from "@tanstack/react-form";
const form = useForm({
defaultValues: { name: "", email: "" },
onSubmit: async ({ value }) => {
await submitToApi(value);
},
});
return (
<form
onSubmit={(e) => {
e.preventDefault();
form.handleSubmit();
}}
>
<form.Field
name="email"
children={(field) => (
<input
value={field.state.value}
onBlur={field.handleBlur}
onChange={(e) => field.handleChange(e.target.value)}
/>
)}
/>
</form>
);
Key difference from other form libraries: No register, no Controller, no ref forwarding. You always use field.handleChange and field.state.value explicitly.
See examples/core.md for complete form with error display and accessibility.
Pattern 2: Field-Level Validation
Validators are functions on the validators prop. Sync validators return a string (error) or undefined (valid). Async validators use onChangeAsync, onBlurAsync, onSubmitAsync.
<form.Field
name="age"
validators={{
onChange: ({ value }) => (value < 13 ? "Must be 13 or older" : undefined),
onBlurAsync: async ({ value }) => {
const exists = await checkAge(value);
return exists ? undefined : "Age not valid on server";
},
}}
children={(field) => (
<div>
<input
type="number"
value={field.state.value}
onBlur={field.handleBlur}
onChange={(e) => field.handleChange(e.target.valueAsNumber)}
/>
{field.state.meta.errors.map((err) => (
<em key={err} role="alert">
{err}
</em>
))}
</div>
)}
/>
Sync-first gating: When both onBlur and onBlurAsync exist, the async validator only runs if the sync validator passes. Same for onChange/onChangeAsync.
See examples/validation.md for all validation patterns and adapter integration.
Pattern 3: Linked Fields (Cross-Field Validation)
Use onChangeListenTo to re-run a field's validator when another field changes. This solves the stale-validation problem (e.g., confirm password).
<form.Field
name="confirm_password"
validators={{
onChangeListenTo: ["password"],
onChange: ({ value, fieldApi }) => {
if (value !== fieldApi.form.getFieldValue("password")) {
return "Passwords do not match";
}
return undefined;
},
}}
children={(field) => (/* ... */)}
/>
Why this matters: Without onChangeListenTo, changing the password field does not re-validate confirm_password. The error stays stale until the user interacts with the confirm field again.
See examples/validation.md Pattern 4 for a complete linked fields example.
Pattern 4: Array Fields
Use mode="array" on form.Field to get pushValue, removeValue, swapValues, moveValue, and insertValue for dynamic field groups.
<form.Field
name="hobbies"
mode="array"
children={(hobbiesField) => (
<div>
{hobbiesField.state.value.map((_, i) => (
<div key={i}>
<form.Field
name={`hobbies[${i}].name`}
children={(field) => (
<input
value={field.state.value}
onChange={(e) => field.handleChange(e.target.value)}
/>
)}
/>
<button type="button" onClick={() => hobbiesField.removeValue(i)}>
Remove
</button>
</div>
))}
<button
type="button"
onClick={() => hobbiesField.pushValue({ name: "" })}
>
Add hobby
</button>
</div>
)}
/>
Important: pushValue requires a complete object matching the array item shape. Partial objects will cause type errors.
See examples/arrays.md for a complete dynamic list form.
Pattern 5: Form-Level Validation
Validators on useForm apply to the entire form. Use onSubmitAsync for server-side validation that returns field-specific errors.
const form = useForm({
defaultValues: { username: "", age: 0 },
validators: {
onSubmitAsync: async ({ value }) => {
const errors = await validateOnServer(value);
if (errors) {
return {
form: "Submission failed",
fields: {
username: errors.username,
age: errors.age,
},
};
}
return null;
},
},
});
Return shape: { form?: string, fields: Record<string, string> } — the form key is optional for form-level errors, fields maps field names to their error messages. Return null when valid.
See examples/validation.md Pattern 3 for complete form-level validation.
Pattern 6: createFormHook (App-Wide Composition)
Use createFormHook to share custom field components and form components across the app. This eliminates boilerplate and enforces consistency.
import { createFormHookContexts, createFormHook } from "@tanstack/react-form";
export const { fieldContext, formContext, useFieldContext } =
createFormHookContexts();
export const { useAppForm, withForm } = createFormHook({
fieldContext,
formContext,
fieldComponents: {
TextField: TextFieldComponent,
SelectField: SelectFieldComponent,
},
formComponents: {
SubmitButton: SubmitButtonComponent,
},
});
Usage: useAppForm accepts all useForm options. Registered fieldComponents and formComponents are available on the returned form instance: form.AppField for custom field components, form.AppForm for form-level components.
See examples/composition.md for the full factory setup and custom component patterns.
Pattern 7: Listeners (Side Effects)
Listeners react to field events and perform side effects like resetting related fields. Use the listeners prop on form.Field.
<form.Field
name="country"
listeners={{
onChange: ({ value }) => {
form.setFieldValue("province", "");
},
}}
children={(field) => (/* ... */)}
/>
Available events: onChange, onBlur, onMount, onSubmit. Listeners are for side effects only — they do not return validation errors.
See examples/composition.md Pattern 3 for a complete country/province cascade.
Pattern 8: form.Subscribe for Reactive UI
Use form.Subscribe to reactively render UI based on form state without re-rendering the entire form. Takes a selector to pick specific state.
<form.Subscribe
selector={(state) => [state.canSubmit, state.isSubmitting]}
children={([canSubmit, isSubmitting]) => (
<button type="submit" disabled={!canSubmit || isSubmitting}>
{isSubmitting ? "Submitting..." : "Submit"}
</button>
)}
/>
Why this matters: Without form.Subscribe, reading form.state directly causes the parent component to re-render on every state change. The selector narrows the subscription.
</patterns>
<red_flags>
RED FLAGS
High Priority Issues:
- Using
registerorControllerpatterns — TanStack Form usesform.Fieldwithchildrenrender prop, not register/Controller - Missing
defaultValuesinuseForm— types cannot be inferred, fields start asundefined - Calling
form.handleSubmit()withoute.preventDefault()— causes page reload - Reading
form.statedirectly in the component body — causes full re-render on every change; useform.SubscribeoruseStore
Medium Priority Issues:
- Using
onChangevalidator for expensive checks — useonChangeAsyncwith debounce oronBlurAsyncinstead - Providing partial objects to
pushValuein array fields — must provide complete objects matching the array item type - Not using
onChangeListenTofor cross-field validation — related field errors go stale - Wrapping
form.handleSubmit()in another async function without error handling —handleSubmitdoes not catch errors thrown inonSubmit
Gotchas & Edge Cases:
field.state.meta.errorsis always an array — never compare with===, always.map()or.length- Sync validators gate async validators — if
onChangefails,onChangeAsyncdoes not run - Form-level
onSubmitAsyncvalidator returns{ fields: { fieldName: "error" } }— not the same shape as field-level validators field.state.meta.isTouchedonly becomestrueafterhandleBlurfires — not on firsthandleChange- Array field access uses bracket notation:
name={items[${i}].name}— not dot notation likeitems.${i}.name form.Subscribeuses aselectorprop to pick state — passing no selector subscribes to everythingcreateFormHookcomponents are available asform.AppFieldandform.AppForm— not onform.Field
</red_flags>
<critical_reminders>
CRITICAL REMINDERS
All code must follow project conventions in CLAUDE.md
(You MUST provide defaultValues to useForm — TanStack Form infers field types from them)
(You MUST use form.Field with the children render prop — TanStack Form does not use register or Controller)
(You MUST use the validators prop for validation — NOT inline rules or external resolver wrappers)
(You MUST handle field.state.meta.errors as an array — always .map() over errors)
(You MUST call form.handleSubmit() inside the form's onSubmit handler with e.preventDefault())
Failure to follow these rules will break form state, lose type safety, and produce incorrect validation behavior.
</critical_reminders>