docs-i18n 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/app/utils/content-loader.ts +4 -0
- package/template/app/utils/docs.server.ts +7 -0
- package/template/content/blog/en/announcing-query-v5.md +110 -0
- package/template/content/blog/en/hello-world.md +26 -0
- package/template/content/blog/en/i18n-best-practices.md +57 -0
- package/template/content/blog/en/react-query-vs-swr.md +100 -0
- package/template/content/blog/en/state-management-2024.md +143 -0
- package/template/content/blog/en/tanstack-router-1.0.md +121 -0
- package/template/content/blog/ja/announcing-query-v5.md +110 -0
- package/template/content/blog/ja/hello-world.md +26 -0
- package/template/content/blog/zh-hans/announcing-query-v5.md +93 -0
- package/template/content/blog/zh-hans/hello-world.md +26 -0
- package/template/content/docs-i18n/docs.config.json +25 -0
- package/template/content/docs-i18n/en/admin.md +143 -0
- package/template/content/docs-i18n/en/architecture.md +222 -0
- package/template/content/docs-i18n/en/cli.md +324 -0
- package/template/content/docs-i18n/en/configuration.md +331 -0
- package/template/content/docs-i18n/en/deployment.md +209 -0
- package/template/content/docs-i18n/en/getting-started.md +168 -0
- package/template/content/docs.config.json +25 -0
- package/template/content/en/admin.md +151 -0
- package/template/content/en/architecture.md +222 -0
- package/template/content/en/cli.md +269 -0
- package/template/content/en/configuration.md +331 -0
- package/template/content/en/deployment.md +209 -0
- package/template/content/en/getting-started.md +168 -0
- package/template/content/form/docs.config.json +18 -0
- package/template/content/form/en/guides/validation.md +175 -0
- package/template/content/form/en/installation.md +63 -0
- package/template/content/form/en/overview.md +71 -0
- package/template/content/form/en/quick-start.md +121 -0
- package/template/content/form/ja/installation.md +63 -0
- package/template/content/form/ja/overview.md +71 -0
- package/template/content/form/zh-hans/installation.md +63 -0
- package/template/content/form/zh-hans/overview.md +71 -0
- package/template/content/query/docs.config.json +32 -0
- package/template/content/query/en/guides/mutations.md +126 -0
- package/template/content/query/en/guides/pagination.md +98 -0
- package/template/content/query/en/guides/queries.md +120 -0
- package/template/content/query/en/installation.md +78 -0
- package/template/content/query/en/overview.md +72 -0
- package/template/content/query/en/quick-start.md +108 -0
- package/template/content/query/ja/installation.md +78 -0
- package/template/content/query/ja/overview.md +72 -0
- package/template/content/query/zh-hans/guides/mutations.md +126 -0
- package/template/content/query/zh-hans/guides/pagination.md +98 -0
- package/template/content/query/zh-hans/guides/queries.md +120 -0
- package/template/content/query/zh-hans/installation.md +95 -0
- package/template/content/query/zh-hans/overview.md +72 -0
- package/template/content/query/zh-hans/quick-start.md +108 -0
- package/template/content/router/docs.config.json +18 -0
- package/template/content/router/en/guides/routing-concepts.md +131 -0
- package/template/content/router/en/installation.md +57 -0
- package/template/content/router/en/overview.md +74 -0
- package/template/content/router/en/quick-start.md +88 -0
- package/template/content/router/ja/installation.md +57 -0
- package/template/content/router/ja/overview.md +78 -0
- package/template/content/router/zh-hans/guides/routing-concepts.md +131 -0
- package/template/content/router/zh-hans/installation.md +57 -0
- package/template/content/router/zh-hans/overview.md +81 -0
- package/template/content/router/zh-hans/quick-start.md +88 -0
- package/template/content/table/docs.config.json +18 -0
- package/template/content/table/en/guides/column-definitions.md +135 -0
- package/template/content/table/en/installation.md +56 -0
- package/template/content/table/en/overview.md +79 -0
- package/template/content/table/en/quick-start.md +112 -0
- package/template/content/table/ja/installation.md +56 -0
- package/template/content/table/ja/overview.md +79 -0
- package/template/content/table/zh-hans/installation.md +56 -0
- package/template/content/table/zh-hans/overview.md +79 -0
- package/template/content/virtual/docs.config.json +18 -0
- package/template/content/virtual/en/guides/dynamic-sizing.md +129 -0
- package/template/content/virtual/en/installation.md +57 -0
- package/template/content/virtual/en/overview.md +74 -0
- package/template/content/virtual/en/quick-start.md +114 -0
- package/template/content/virtual/ja/installation.md +57 -0
- package/template/content/virtual/ja/overview.md +74 -0
- package/template/content/virtual/zh-hans/installation.md +57 -0
- package/template/content/virtual/zh-hans/overview.md +74 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sections": [
|
|
3
|
+
{
|
|
4
|
+
"label": "Getting Started",
|
|
5
|
+
"children": [
|
|
6
|
+
{ "label": "Overview", "to": "overview" },
|
|
7
|
+
{ "label": "Installation", "to": "installation" },
|
|
8
|
+
{ "label": "Quick Start", "to": "quick-start" }
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"label": "Guides",
|
|
13
|
+
"children": [
|
|
14
|
+
{ "label": "Validation", "to": "guides/validation" }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Validation
|
|
3
|
+
description: Learn how to validate form fields with TanStack Form
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Validation
|
|
7
|
+
|
|
8
|
+
TanStack Form provides powerful, flexible validation that works at both the field level and form level. Validation can run on change, on blur, on submit, or asynchronously.
|
|
9
|
+
|
|
10
|
+
## Field-Level Validation
|
|
11
|
+
|
|
12
|
+
The most common approach is to validate individual fields. You can add validators directly to each field:
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { useForm } from '@tanstack/react-form'
|
|
16
|
+
|
|
17
|
+
function SignupForm() {
|
|
18
|
+
const form = useForm({
|
|
19
|
+
defaultValues: {
|
|
20
|
+
username: '',
|
|
21
|
+
email: '',
|
|
22
|
+
password: '',
|
|
23
|
+
},
|
|
24
|
+
onSubmit: async ({ value }) => {
|
|
25
|
+
console.log('Form submitted:', value)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<form
|
|
31
|
+
onSubmit={(e) => {
|
|
32
|
+
e.preventDefault()
|
|
33
|
+
form.handleSubmit()
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<form.Field
|
|
37
|
+
name="username"
|
|
38
|
+
validators={{
|
|
39
|
+
onChange: ({ value }) => {
|
|
40
|
+
if (value.length < 3) {
|
|
41
|
+
return 'Username must be at least 3 characters'
|
|
42
|
+
}
|
|
43
|
+
return undefined
|
|
44
|
+
},
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
{(field) => (
|
|
48
|
+
<div>
|
|
49
|
+
<label htmlFor={field.name}>Username</label>
|
|
50
|
+
<input
|
|
51
|
+
id={field.name}
|
|
52
|
+
value={field.state.value}
|
|
53
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
54
|
+
onBlur={field.handleBlur}
|
|
55
|
+
/>
|
|
56
|
+
{field.state.meta.errors.length > 0 && (
|
|
57
|
+
<p className="text-red-500">{field.state.meta.errors.join(', ')}</p>
|
|
58
|
+
)}
|
|
59
|
+
</div>
|
|
60
|
+
)}
|
|
61
|
+
</form.Field>
|
|
62
|
+
|
|
63
|
+
<button type="submit">Sign Up</button>
|
|
64
|
+
</form>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Validation Timing
|
|
70
|
+
|
|
71
|
+
TanStack Form supports multiple validation timings:
|
|
72
|
+
|
|
73
|
+
| Timing | When it runs | Use case |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `onChange` | Every keystroke | Real-time feedback |
|
|
76
|
+
| `onBlur` | When field loses focus | Less intrusive UX |
|
|
77
|
+
| `onSubmit` | When form is submitted | Final validation only |
|
|
78
|
+
| `onChangeAsync` | Debounced on change | API-backed validation |
|
|
79
|
+
| `onBlurAsync` | Async on blur | Server-side checks |
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<form.Field
|
|
83
|
+
name="email"
|
|
84
|
+
validators={{
|
|
85
|
+
onChange: ({ value }) => {
|
|
86
|
+
if (!value.includes('@')) return 'Invalid email format'
|
|
87
|
+
},
|
|
88
|
+
onChangeAsyncDebounceMs: 500,
|
|
89
|
+
onChangeAsync: async ({ value }) => {
|
|
90
|
+
const available = await checkEmailAvailable(value)
|
|
91
|
+
if (!available) return 'Email already taken'
|
|
92
|
+
},
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
{(field) => <input {...field} />}
|
|
96
|
+
</form.Field>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Schema Validation with Adapters
|
|
100
|
+
|
|
101
|
+
TanStack Form integrates with popular schema validation libraries through adapters:
|
|
102
|
+
|
|
103
|
+
### Zod Adapter
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm install @tanstack/zod-form-adapter zod
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import { zodValidator } from '@tanstack/zod-form-adapter'
|
|
111
|
+
import { z } from 'zod'
|
|
112
|
+
|
|
113
|
+
const form = useForm({
|
|
114
|
+
defaultValues: { email: '' },
|
|
115
|
+
onSubmit: async ({ value }) => console.log(value),
|
|
116
|
+
validatorAdapter: zodValidator(),
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Then in fields:
|
|
120
|
+
<form.Field
|
|
121
|
+
name="email"
|
|
122
|
+
validators={{
|
|
123
|
+
onChange: z.string().email('Invalid email'),
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
{(field) => <input />}
|
|
127
|
+
</form.Field>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Valibot Adapter
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install @tanstack/valibot-form-adapter valibot
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
import { valibotValidator } from '@tanstack/valibot-form-adapter'
|
|
138
|
+
import * as v from 'valibot'
|
|
139
|
+
|
|
140
|
+
const form = useForm({
|
|
141
|
+
defaultValues: { email: '' },
|
|
142
|
+
onSubmit: async ({ value }) => console.log(value),
|
|
143
|
+
validatorAdapter: valibotValidator(),
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
> [!NOTE]
|
|
148
|
+
> Schema adapters let you use the same schema definitions for both form validation and API validation, keeping your validation logic DRY.
|
|
149
|
+
|
|
150
|
+
## Form-Level Validation
|
|
151
|
+
|
|
152
|
+
You can also validate the entire form at once, useful for cross-field validation:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
const form = useForm({
|
|
156
|
+
defaultValues: {
|
|
157
|
+
password: '',
|
|
158
|
+
confirmPassword: '',
|
|
159
|
+
},
|
|
160
|
+
validators: {
|
|
161
|
+
onChange: ({ value }) => {
|
|
162
|
+
if (value.password !== value.confirmPassword) {
|
|
163
|
+
return 'Passwords do not match'
|
|
164
|
+
}
|
|
165
|
+
return undefined
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
onSubmit: async ({ value }) => {
|
|
169
|
+
// handle submit
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
> [!WARNING]
|
|
175
|
+
> Form-level validators run on every field change by default. For expensive validation logic, use `onBlur` or `onSubmit` timing instead.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Installation
|
|
3
|
+
description: How to install TanStack Form in your project
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Installation
|
|
7
|
+
|
|
8
|
+
## React
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @tanstack/react-form
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @tanstack/react-form
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add @tanstack/react-form
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bun add @tanstack/react-form
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Vue
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @tanstack/vue-form
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Angular
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @tanstack/angular-form
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Validation Adapters
|
|
39
|
+
|
|
40
|
+
TanStack Form supports popular validation libraries via adapters:
|
|
41
|
+
|
|
42
|
+
### Zod
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @tanstack/zod-form-adapter zod
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Valibot
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @tanstack/valibot-form-adapter valibot
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Yup
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @tanstack/yup-form-adapter yup
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Requirements
|
|
61
|
+
|
|
62
|
+
- TypeScript 5.0+
|
|
63
|
+
- React 18+ / Vue 3+ / Angular 17+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TanStack Form Overview
|
|
3
|
+
description: Headless, performant, and type-safe form state management
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TanStack Form
|
|
7
|
+
|
|
8
|
+
TanStack Form is a headless, performant, and type-safe form state management library for TS/JS, React, Vue, and Angular.
|
|
9
|
+
|
|
10
|
+
## Why TanStack Form?
|
|
11
|
+
|
|
12
|
+
Most form libraries either sacrifice type safety for convenience or are tightly coupled to a specific framework. TanStack Form gives you both — full type safety from form values to validation errors, with adapters for React, Vue, and Angular.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Type-Safe** — Full TypeScript inference for form values, field names, and validation
|
|
17
|
+
- **Framework Agnostic** — Works with React, Vue, Angular, and more
|
|
18
|
+
- **Headless** — No UI opinions, bring your own components
|
|
19
|
+
- **Performant** — Field-level subscriptions, no unnecessary re-renders
|
|
20
|
+
- **Validation** — Built-in sync and async validation with adapter support for Zod, Valibot, and Yup
|
|
21
|
+
- **Arrays & Dynamic Fields** — First-class support for array fields
|
|
22
|
+
|
|
23
|
+
## Basic Example
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useForm } from '@tanstack/react-form'
|
|
27
|
+
|
|
28
|
+
function SignupForm() {
|
|
29
|
+
const form = useForm({
|
|
30
|
+
defaultValues: {
|
|
31
|
+
firstName: '',
|
|
32
|
+
lastName: '',
|
|
33
|
+
email: '',
|
|
34
|
+
},
|
|
35
|
+
onSubmit: async ({ value }) => {
|
|
36
|
+
console.log(value)
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<form
|
|
42
|
+
onSubmit={(e) => {
|
|
43
|
+
e.preventDefault()
|
|
44
|
+
form.handleSubmit()
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<form.Field
|
|
48
|
+
name="firstName"
|
|
49
|
+
validators={{
|
|
50
|
+
onChange: ({ value }) =>
|
|
51
|
+
!value ? 'First name is required' : undefined,
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
{(field) => (
|
|
55
|
+
<div>
|
|
56
|
+
<label>First Name</label>
|
|
57
|
+
<input
|
|
58
|
+
value={field.state.value}
|
|
59
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
60
|
+
/>
|
|
61
|
+
{field.state.meta.errors.length > 0 && (
|
|
62
|
+
<span>{field.state.meta.errors.join(', ')}</span>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
)}
|
|
66
|
+
</form.Field>
|
|
67
|
+
<button type="submit">Submit</button>
|
|
68
|
+
</form>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Quick Start
|
|
3
|
+
description: Get up and running with TanStack Form
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Quick Start
|
|
7
|
+
|
|
8
|
+
## Create a Form
|
|
9
|
+
|
|
10
|
+
Use the `useForm` hook to create a form instance:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { useForm } from '@tanstack/react-form'
|
|
14
|
+
|
|
15
|
+
function MyForm() {
|
|
16
|
+
const form = useForm({
|
|
17
|
+
defaultValues: {
|
|
18
|
+
username: '',
|
|
19
|
+
password: '',
|
|
20
|
+
},
|
|
21
|
+
onSubmit: async ({ value }) => {
|
|
22
|
+
// Handle form submission
|
|
23
|
+
await loginUser(value)
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<form
|
|
29
|
+
onSubmit={(e) => {
|
|
30
|
+
e.preventDefault()
|
|
31
|
+
form.handleSubmit()
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
{/* Fields go here */}
|
|
35
|
+
<button type="submit">Submit</button>
|
|
36
|
+
</form>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Add Fields
|
|
42
|
+
|
|
43
|
+
Use `form.Field` to create type-safe form fields:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
<form.Field name="username">
|
|
47
|
+
{(field) => (
|
|
48
|
+
<div>
|
|
49
|
+
<label htmlFor={field.name}>Username</label>
|
|
50
|
+
<input
|
|
51
|
+
id={field.name}
|
|
52
|
+
value={field.state.value}
|
|
53
|
+
onBlur={field.handleBlur}
|
|
54
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
)}
|
|
58
|
+
</form.Field>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Add Validation
|
|
62
|
+
|
|
63
|
+
Add field-level validation with sync or async validators:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
<form.Field
|
|
67
|
+
name="email"
|
|
68
|
+
validators={{
|
|
69
|
+
onChange: ({ value }) => {
|
|
70
|
+
if (!value) return 'Email is required'
|
|
71
|
+
if (!value.includes('@')) return 'Invalid email address'
|
|
72
|
+
return undefined
|
|
73
|
+
},
|
|
74
|
+
onChangeAsyncDebounceMs: 500,
|
|
75
|
+
onChangeAsync: async ({ value }) => {
|
|
76
|
+
const exists = await checkEmailExists(value)
|
|
77
|
+
return exists ? 'Email already taken' : undefined
|
|
78
|
+
},
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
{(field) => (
|
|
82
|
+
<div>
|
|
83
|
+
<input
|
|
84
|
+
value={field.state.value}
|
|
85
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
86
|
+
/>
|
|
87
|
+
{field.state.meta.errors.map((error) => (
|
|
88
|
+
<p key={error} className="text-red-500">{error}</p>
|
|
89
|
+
))}
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
</form.Field>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Using Zod Validation
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { zodValidator } from '@tanstack/zod-form-adapter'
|
|
99
|
+
import { z } from 'zod'
|
|
100
|
+
|
|
101
|
+
const form = useForm({
|
|
102
|
+
defaultValues: { email: '' },
|
|
103
|
+
validatorAdapter: zodValidator(),
|
|
104
|
+
onSubmit: async ({ value }) => {
|
|
105
|
+
console.log(value)
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// Then in your field:
|
|
110
|
+
<form.Field
|
|
111
|
+
name="email"
|
|
112
|
+
validators={{
|
|
113
|
+
onChange: z.string().email('Invalid email'),
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
{(field) => /* ... */}
|
|
117
|
+
</form.Field>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
> [!NOTE]
|
|
121
|
+
> Async validators support debouncing out of the box with `onChangeAsyncDebounceMs`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: インストール
|
|
3
|
+
description: プロジェクトに TanStack Form をインストールする方法
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# インストール
|
|
7
|
+
|
|
8
|
+
## React
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @tanstack/react-form
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @tanstack/react-form
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add @tanstack/react-form
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bun add @tanstack/react-form
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Vue
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @tanstack/vue-form
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Angular
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @tanstack/angular-form
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## バリデーションアダプター
|
|
39
|
+
|
|
40
|
+
TanStack Form はアダプターを通じて人気のバリデーションライブラリをサポートしています:
|
|
41
|
+
|
|
42
|
+
### Zod
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @tanstack/zod-form-adapter zod
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Valibot
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @tanstack/valibot-form-adapter valibot
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Yup
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @tanstack/yup-form-adapter yup
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 必要要件
|
|
61
|
+
|
|
62
|
+
- TypeScript 5.0+
|
|
63
|
+
- React 18+ / Vue 3+ / Angular 17+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TanStack Form 概要
|
|
3
|
+
description: ヘッドレスで高性能、型安全なフォーム状態管理
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TanStack Form
|
|
7
|
+
|
|
8
|
+
TanStack Form は、TS/JS、React、Vue、Angular 向けのヘッドレスで高性能、型安全なフォーム状態管理ライブラリです。
|
|
9
|
+
|
|
10
|
+
## なぜ TanStack Form を選ぶのか?
|
|
11
|
+
|
|
12
|
+
ほとんどのフォームライブラリは、利便性のために型安全性を犠牲にするか、特定のフレームワークに密結合しています。TanStack Form はその両方を実現します。フォームの値からバリデーションエラーまで完全な型安全性を提供し、React、Vue、Angular のアダプターを備えています。
|
|
13
|
+
|
|
14
|
+
## 特徴
|
|
15
|
+
|
|
16
|
+
- **型安全** — フォームの値、フィールド名、バリデーションの完全な TypeScript 推論
|
|
17
|
+
- **フレームワーク非依存** — React、Vue、Angular などで動作
|
|
18
|
+
- **ヘッドレス** — UI の制約なし、独自のコンポーネントを使用
|
|
19
|
+
- **高性能** — フィールドレベルのサブスクリプション、不要な再レンダリングなし
|
|
20
|
+
- **バリデーション** — 組み込みの同期・非同期バリデーション、Zod、Valibot、Yup アダプターをサポート
|
|
21
|
+
- **配列と動的フィールド** — 配列フィールドのファーストクラスサポート
|
|
22
|
+
|
|
23
|
+
## 基本的な例
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useForm } from '@tanstack/react-form'
|
|
27
|
+
|
|
28
|
+
function SignupForm() {
|
|
29
|
+
const form = useForm({
|
|
30
|
+
defaultValues: {
|
|
31
|
+
firstName: '',
|
|
32
|
+
lastName: '',
|
|
33
|
+
email: '',
|
|
34
|
+
},
|
|
35
|
+
onSubmit: async ({ value }) => {
|
|
36
|
+
console.log(value)
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<form
|
|
42
|
+
onSubmit={(e) => {
|
|
43
|
+
e.preventDefault()
|
|
44
|
+
form.handleSubmit()
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<form.Field
|
|
48
|
+
name="firstName"
|
|
49
|
+
validators={{
|
|
50
|
+
onChange: ({ value }) =>
|
|
51
|
+
!value ? 'First name is required' : undefined,
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
{(field) => (
|
|
55
|
+
<div>
|
|
56
|
+
<label>First Name</label>
|
|
57
|
+
<input
|
|
58
|
+
value={field.state.value}
|
|
59
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
60
|
+
/>
|
|
61
|
+
{field.state.meta.errors.length > 0 && (
|
|
62
|
+
<span>{field.state.meta.errors.join(', ')}</span>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
)}
|
|
66
|
+
</form.Field>
|
|
67
|
+
<button type="submit">Submit</button>
|
|
68
|
+
</form>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 安装
|
|
3
|
+
description: 如何在项目中安装 TanStack Form
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 安装
|
|
7
|
+
|
|
8
|
+
## React
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @tanstack/react-form
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @tanstack/react-form
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add @tanstack/react-form
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bun add @tanstack/react-form
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Vue
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @tanstack/vue-form
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Angular
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @tanstack/angular-form
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 验证适配器
|
|
39
|
+
|
|
40
|
+
TanStack Form 通过适配器支持流行的验证库:
|
|
41
|
+
|
|
42
|
+
### Zod
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @tanstack/zod-form-adapter zod
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Valibot
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @tanstack/valibot-form-adapter valibot
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Yup
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @tanstack/yup-form-adapter yup
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 环境要求
|
|
61
|
+
|
|
62
|
+
- TypeScript 5.0+
|
|
63
|
+
- React 18+ / Vue 3+ / Angular 17+
|