Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

FieldGroupFieldComponent.md

81 lines2.0 KB

1---
2id: FieldGroupFieldComponent
3title: FieldGroupFieldComponent
4---
5​
6Defined in: [packages/react-form/src/FieldGroup/FieldGroupApi.public.ts:20](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/FieldGroupApi.public.ts#L20)
7​
8## Type Parameters
9​
10### TFieldData
11​
12`TFieldData`
13​
14### TFieldComponents
15​
16`TFieldComponents` *extends* [`ReactComponentTree`](../type-aliases/ReactComponentTree.md)
17​
18```ts
19FieldGroupFieldComponent<TFieldName>(props): ReactNode;
20```
21​
22Defined in: [packages/react-form/src/FieldGroup/FieldGroupApi.public.ts:67](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/FieldGroupApi.public.ts#L67)
23​
24Renders a field from this field group.
25​
26The field name is automatically connected to the form section where the
27field group is used.
28​
29## Type Parameters
30​
31### TFieldName
32​
33`TFieldName` *extends* `string`
34​
35## Parameters
36​
37### props
38​
39[`ReactFormFieldProps`](ReactFormFieldProps.md)\<`TFieldData`, `TFieldName`, `DeepValue`\<`TFieldData`, `TFieldName`\>, `FieldValidators`\<`TFieldData`, `TFieldName`, `DeepValue`\<`TFieldData`, `TFieldName`\>\>, `ValidationIssue`, `unknown`, `FormErrorTypes`\<`ValidationIssue`, `ValidationIssue`\>, `TFieldComponents`\>
40​
41## Returns
42​
43`ReactNode`
44​
45## Example
46​
47```tsx
48const passwordFieldGroup = defineFieldGroup(({ strict }) => ({
49 password: strict<string>(),
50 confirmPassword: strict<string>(),
51}))
52​
53interface PasswordFieldsProps {
54 fields: typeof passwordFieldGroup.fields
56​
57function PasswordFields({ fields }: PasswordFieldsProps) {
58 return (
59 <>
60 <fields.Field name="password">
61 {(field) => (
62 <input
63 type="password"
64 value={field.value}
65 onChange={(event) => field.handleChange(event.target.value)}
66 />
67 )}
68 </fields.Field>
69 <fields.Field name="confirmPassword">
70 {(field) => (
71 <input
72 type="password"
73 value={field.value}
74 onChange={(event) => field.handleChange(event.target.value)}
75 />
76 )}
77 </fields.Field>
78 </>
79 )
81```