Skip to content

Commit 1fb28c5

Browse files
committed
fix: refactor to flat generics with consistent names & patterns
1 parent 46b49ca commit 1fb28c5

File tree

15 files changed

+252
-225
lines changed

15 files changed

+252
-225
lines changed

docs/framework/react/reference/Field.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,47 @@ id: field
33
title: Field
44
---
55

6-
### `FieldComponent<TFormData>`
6+
### `FieldComponent<TParentData>`
77

88
A type alias representing a field component for a specific form data type.
99

1010
```tsx
11-
export type FieldComponent = <TField extends DeepKeys<TFormData>>({
11+
export type FieldComponent = <TField extends DeepKeys<TParentData>>({
1212
children,
1313
...fieldOptions
1414
}: {
15-
children: (fieldApi: FieldApi<DeepValue<TFormData, TField>, TFormData>) => any
15+
children: (
16+
fieldApi: FieldApi<DeepValue<TParentData, TField>, TParentData>,
17+
) => any
1618
name: TField
17-
} & Omit<FieldOptions<DeepValue<TFormData, TField>, TFormData>, 'name'>) => any
19+
} & Omit<
20+
FieldOptions<DeepValue<TParentData, TField>, TParentData>,
21+
'name'
22+
>) => any
1823
```
1924
2025
A function component that takes field options and a render function as children and returns a React component.
2126
2227
### `Field`
2328
2429
```tsx
25-
export function Field<TData, TFormData>({
30+
export function Field<TData, TParentData>({
2631
children,
2732
...fieldOptions
28-
}: { children: (fieldApi: FieldApi<TData, TFormData>) => any } & FieldOptions<
33+
}: { children: (fieldApi: FieldApi<TData, TParentData>) => any } & FieldOptions<
2934
TData,
30-
TFormData
35+
TParentData
3136
>): any
3237
```
3338

3439
A functional React component that renders a form field.
3540

3641
- ```tsx
37-
children: (fieldApi: FieldApi<TData, TFormData>) => any
42+
children: (fieldApi: FieldApi<TData, TParentData>) => any
3843
```
3944
- A render function that takes a field API instance and returns a React element.
4045
- ```tsx
41-
fieldOptions: FieldOptions<TData, TFormData>
46+
fieldOptions: FieldOptions<TData, TParentData>
4247
```
4348
- The field options.
4449

@@ -47,14 +52,14 @@ The `Field` component uses the `useField` hook internally to manage the field in
4752
### `createFieldComponent`
4853

4954
```tsx
50-
export function createFieldComponent<TFormData>(
51-
formApi: FormApi<TFormData>,
52-
): FieldComponent<TFormData>
55+
export function createFieldComponent<TParentData>(
56+
formApi: FormApi<TParentData>,
57+
): FieldComponent<TParentData>
5358
```
5459

5560
A factory function that creates a connected field component for a specific form API instance.
5661

5762
- ```tsx
58-
formApi: FormApi<TFormData>
63+
formApi: FormApi<TParentData>
5964
```
6065
- The form API instance to connect the field component to.

docs/framework/react/reference/fieldApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ id: fieldApi
33
title: Field API
44
---
55

6-
### `FieldApi<TData, TFormData>`
6+
### `FieldApi<TData, TParentData>`
77

88
When using `@tanstack/react-form`, the [core field API](../../reference/fieldApi) is extended with additional methods for React-specific functionality:
99

1010
- ```tsx
11-
Field: FieldComponent<TData, TFormData>
11+
Field: FieldComponent<TData, TParentData>
1212
```
1313
- A pre-bound and type-safe sub-field component using this field as a root.

docs/framework/react/reference/useField.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@ id: useField
33
title: useField
44
---
55

6-
### `UseField<TFormData>`
6+
### `UseField<TParentData>`
77

88
A type representing a hook for using a field in a form with the given form data type.
99

1010
```tsx
11-
export type UseField = <TField extends DeepKeys<TFormData>>(
11+
export type UseField = <TField extends DeepKeys<TParentData>>(
1212
opts?: { name: TField } & FieldOptions<
13-
DeepValue<TFormData, TField>,
14-
TFormData
13+
DeepValue<TParentData, TField>,
14+
TParentData
1515
>,
16-
) => FieldApi<DeepValue<TFormData, TField>, TFormData>
16+
) => FieldApi<DeepValue<TParentData, TField>, TParentData>
1717
```
1818
1919
- A function that takes an optional object with a `name` property and field options, and returns a `FieldApi` instance for the specified field.
2020
2121
### `useField`
2222
2323
```tsx
24-
export function useField<TData, TFormData>(
25-
opts: FieldOptions<TData, TFormData>,
26-
): FieldApi<TData, TFormData>
24+
export function useField<TData, TParentData>(
25+
opts: FieldOptions<TData, TParentData>,
26+
): FieldApi<TData, TParentData>
2727
```
2828

2929
A hook for managing a field in a form.
3030

3131
- ```tsx
32-
opts: FieldOptions<TData, TFormData>
32+
opts: FieldOptions<TData, TParentData>
3333
```
3434
- An object with field options.
3535

3636
#### Returns
3737

3838
- ```tsx
39-
FieldApi<TData, TFormData>
39+
FieldApi<TData, TParentData>
4040
```
4141
- The `FieldApi` instance for the specified field.
4242

4343
### `createUseField`
4444

4545
```tsx
46-
export function createUseField<TFormData>(
47-
formApi: FormApi<TFormData>,
48-
): UseField<TFormData>
46+
export function createUseField<TParentData>(
47+
formApi: FormApi<TParentData>,
48+
): UseField<TParentData>
4949
```
5050

5151
A function that creates a `UseField` hook bound to the given `formApi`.

docs/reference/fieldApi.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Normally, you will not need to create a new `FieldApi` instance directly. Instea
1111
const fieldApi: FieldApi<TData> = new FieldApi(formOptions: Field Options<TData>)
1212
```
1313

14-
### `FieldOptions<TData, TFormData>`
14+
### `FieldOptions<TData, TParentData>`
1515

1616
An object type representing the options for a field in a form.
1717

1818
- ```tsx
1919
name
2020
```
21-
- The field name. If `TFormData` is `unknown`, the type will be `string`. Otherwise, it will be `DeepKeys<TFormData>`.
21+
- The field name. If `TParentData` is `unknown`, the type will be `string`. Otherwise, it will be `DeepKeys<TParentData>`.
2222
- ```tsx
2323
defaultValue?: TData
2424
```
@@ -30,19 +30,19 @@ An object type representing the options for a field in a form.
3030
- An optional object with default metadata for the field.
3131

3232
- ```tsx
33-
onMount?: (formApi: FieldApi<TData, TFormData>) => void
33+
onMount?: (formApi: FieldApi<TData, TParentData>) => void
3434
```
3535

36-
- An optional function that takes a param of `formApi` which is a generic type of `TData` and `TFormData`
36+
- An optional function that takes a param of `formApi` which is a generic type of `TData` and `TParentData`
3737

3838
- ```tsx
39-
onChange?: ValidateFn<TData, TFormData>
39+
onChange?: ValidateFn<TData, TParentData>
4040
```
4141

42-
- An optional property that takes a `ValidateFn` which is a generic of `TData` and `TFormData`
42+
- An optional property that takes a `ValidateFn` which is a generic of `TData` and `TParentData`
4343

4444
- ```tsx
45-
onChangeAsync?: ValidateAsyncFn<TData, TFormData>
45+
onChangeAsync?: ValidateAsyncFn<TData, TParentData>
4646
```
4747

4848
- An optional property similar to `onChange` but async validation
@@ -55,16 +55,16 @@ An object type representing the options for a field in a form.
5555
- If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds
5656

5757
- ```tsx
58-
onBlur?: ValidateFn<TData, TFormData>
58+
onBlur?: ValidateFn<TData, TParentData>
5959
```
6060

6161
- An optional function, when that run when subscribing to blur event of input
6262

6363
- ```tsx
64-
onBlurAsync?: ValidateAsyncFn<TData, TFormData>
64+
onBlurAsync?: ValidateAsyncFn<TData, TParentData>
6565
```
6666

67-
- An optional function that takes a `ValidateFn` which is a generic of `TData` and `TFormData` happens async
67+
- An optional function that takes a `ValidateFn` which is a generic of `TData` and `TParentData` happens async
6868

6969
```tsx
7070
onBlurAsyncDebounceMs?: number
@@ -110,13 +110,13 @@ An object type representing the metadata of a field in a form.
110110
```
111111
- A flag indicating whether the field is currently being validated.
112112

113-
### `FieldApiOptions<TData, TFormData>`
113+
### `FieldApiOptions<TData, TParentData>`
114114

115115
An object type representing the required options for the `FieldApi` class.
116116

117-
- Inherits from `FieldOptions<TData, TFormData>` with the `form` property set as required.
117+
- Inherits from `FieldOptions<TData, TParentData>` with the `form` property set as required.
118118

119-
### `FieldApi<TData, TFormData>`
119+
### `FieldApi<TData, TParentData>`
120120

121121
A class representing the API for managing a form field.
122122

@@ -127,11 +127,11 @@ A class representing the API for managing a form field.
127127
```
128128
- A unique identifier for the field instance.
129129
- ```tsx
130-
form: FormApi<TFormData>
130+
form: FormApi<TParentData>
131131
```
132132
- A reference to the form API instance.
133133
- ```tsx
134-
name: DeepKeys<TFormData>
134+
name: DeepKeys<TParentData>
135135
```
136136
- The field name.
137137
- ```tsx
@@ -143,14 +143,14 @@ A class representing the API for managing a form field.
143143
```
144144
- The current field state.
145145
- ```tsx
146-
options: RequiredByKey<FieldOptions<TData, TFormData>, 'validateOn'>
146+
options: RequiredByKey<FieldOptions<TData, TParentData>, 'validateOn'>
147147
```
148148
- The field options with the `validateOn` property set as required.
149149

150150
#### Methods
151151

152152
- ```tsx
153-
constructor(opts: FieldApiOptions<TData, TFormData>)
153+
constructor(opts: FieldApiOptions<TData, TParentData>)
154154
```
155155
- Initializes a new `FieldApi` instance.
156156
- ```tsx
@@ -162,7 +162,7 @@ A class representing the API for managing a form field.
162162
```
163163
- Updates the field store with the latest form state.
164164
- ```tsx
165-
update(opts: FieldApiOptions<TData, TFormData>): void
165+
update(opts: FieldApiOptions<TData, TParentData>): void
166166
```
167167
- Updates the field instance with new options.
168168
- ```tsx
@@ -202,7 +202,7 @@ A class representing the API for managing a form field.
202202
```
203203
- Swaps the values at the specified indices.
204204
- ```tsx
205-
getSubField<TName extends DeepKeys<TData>>(name: TName): FieldApi<DeepValue<TData, TName>, TFormData>
205+
getSubField<TName extends DeepKeys<TData>>(name: TName): FieldApi<DeepValue<TData, TName>, TParentData>
206206
```
207207
- Gets a subfield instance.
208208
- ```tsx

0 commit comments

Comments
 (0)