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

FieldGroupArrayFieldComponent.md

78 lines2.0 KB

1---
2id: FieldGroupArrayFieldComponent
3title: FieldGroupArrayFieldComponent
4---
5​
6Defined in: [packages/react-form/src/FieldGroup/FieldGroupApi.public.ts:85](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/FieldGroupApi.public.ts#L85)
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
19FieldGroupArrayFieldComponent<TFieldName>(props): ReactNode;
20```
21​
22Defined in: [packages/react-form/src/FieldGroup/FieldGroupApi.public.ts:129](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/FieldGroupApi.public.ts#L129)
23​
24Renders an array 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* `never`
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 contactFieldGroup = defineFieldGroup(({ strict }) => ({
49 emails: strict<Array<{ value: string }>>(),
50}))
51​
52interface ContactFieldsProps {
53 fields: typeof contactFieldGroup.fields
55​
56function ContactFields({ fields }: ContactFieldsProps) {
57 return (
58 <fields.ArrayField name="emails">
59 {(emails) => (
60 <>
61 {emails.value.map((_, index) => (
62 <fields.Field key={index} name={`emails[${index}].value`}>
63 {(field) => (
64 <input
65 value={field.value}
66 onChange={(event) =>
67 field.handleChange(event.target.value)
68 }
69 />
70 )}
71 </fields.Field>
72 ))}
73 </>
74 )}
75 </fields.ArrayField>
76 )
78```