Open History to see the last commit
1---
2id: defineFieldGroup
3title: defineFieldGroup
4---
5β
6```ts
7const defineFieldGroup: DefineFieldGroupFn<Record<never, never>>;
8```
9β
10Defined in: [packages/react-form/src/FieldGroup/withFields.public.ts:255](https://github.com/TanStack/form/blob/main/packages/react-form/src/FieldGroup/withFields.public.ts#L255)
11β
12Defines a reusable group of virtual fields that can be bound to concrete
13paths in different parent forms.
14β
15Use `strict` when a binding must have exactly the declared value type. Use
16`loose` when a binding may have the declared type or a narrower assignable
17type.
18β
19## Example
20β
21```tsx
22const passwordFieldGroup = defineFieldGroup(({ strict }) => ({
23 password: strict<string>(),
24 confirmPassword: strict<string>(),
25}))
26β
27interface PasswordFieldsProps {
28 fields: typeof passwordFieldGroup.fields
29}
30β
31function PasswordFields({ fields }: PasswordFieldsProps) {
32 return (
33 <>
34 <fields.Field name="password">
35 {(field) => (
36 <input
37 type="password"
38 value={field.value}
39 onChange={(event) => field.handleChange(event.target.value)}
40 />
41 )}
42 </fields.Field>
43 <fields.Field name="confirmPassword">
44 {(field) => (
45 <input
46 type="password"
47 value={field.value}
48 onChange={(event) => field.handleChange(event.target.value)}
49 />
50 )}
51 </fields.Field>
52 </>
53 )
54}
55β
56export const PasswordSection = passwordFieldGroup.bindComponent(
57 PasswordFields,
58 'fields',
59)
60```