Open History to see the last commit
1---
2id: FieldGroupDefinition
3title: FieldGroupDefinition
4---
5β
6Defined in: [packages/react-form/src/FieldGroup/withFields.public.ts:118](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/withFields.public.ts#L118)
7β
8## Type Parameters
9β
10### TFields
11β
12`TFields` *extends* `FieldGroupFields`
13β
14### TFieldComponents
15β
16`TFieldComponents` *extends* [`ReactComponentTree`](../type-aliases/ReactComponentTree.md)
17β
18## Properties
19β
20### bindComponent
21β
22```ts
23bindComponent: FieldGroupWithFieldsFn<ReactFieldGroup<TFields, TFieldComponents>>;
24```
25β
26Defined in: [packages/react-form/src/FieldGroup/withFields.public.ts:191](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/withFields.public.ts#L191)
27β
28Binds a component's field-group API prop to concrete paths in a parent
29form.
30β
31The returned component accepts the original component props except for the
32injected field-group API prop and adds a `form` prop. When every virtual
33field name is already a compatible form path, those paths bind
34automatically when the bindings prop is omitted. A complete bindings map
35can still reroute them. Otherwise, the injected prop name is reused for the
36required virtual-to-concrete field binding map.
37β
38#### Example
39β
40```tsx
41const passwordFieldGroup = defineFieldGroup(({ strict }) => ({
42 password: strict<string>(),
43 confirmPassword: strict<string>(),
44}))
45β
46interface PasswordFieldsProps {
47 fields: typeof passwordFieldGroup.fields
48 legend: string
49}
50β
51function PasswordFields({ fields, legend }: PasswordFieldsProps) {
52 return (
53 <fieldset>
54 <legend>{legend}</legend>
55 <fields.Field name="password">
56 {(field) => (
57 <input
58 type="password"
59 value={field.value}
60 onChange={(event) => field.handleChange(event.target.value)}
61 />
62 )}
63 </fields.Field>
64 <fields.Field name="confirmPassword">
65 {(field) => (
66 <input
67 type="password"
68 value={field.value}
69 onChange={(event) => field.handleChange(event.target.value)}
70 />
71 )}
72 </fields.Field>
73 </fieldset>
74 )
75}
76β
77const PasswordSection = passwordFieldGroup.bindComponent(
78 PasswordFields,
79 'fields',
80)
81β
82<PasswordSection
83 form={form}
84 legend="Choose a password"
85 fields={{
86 password: 'account.password',
87 confirmPassword: 'account.confirmPassword',
88 }}
89/>
90```
91β
92***
93β
94### fields
95β
96```ts
97fields: ReactFieldGroup<TFields, TFieldComponents>;
98```
99β
100Defined in: [packages/react-form/src/FieldGroup/withFields.public.ts:126](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/withFields.public.ts#L126)
101β
102The virtual field-group API injected into the component passed to
103`bindComponent`.