Open History to see the last commit
1---
2id: FieldComponentHelper
3title: FieldComponentHelper
4---
5β
6Defined in: [packages/react-form/src/AppForm/getFormHookHelpers.public.ts:68](https://github.com/TanStack/form/blob/main/packages/react-form/src/AppForm/getFormHookHelpers.public.ts#L68)
7β
8Wraps components that accept a field API prop so App Form can supply that
9prop from field context.
10β
11## Properties
12β
13### loose
14β
15```ts
16loose: <TComponent, TProps, TFieldPropKey>(Component, fieldPropKey) => LooseInjectedFieldComponent<TComponent, TProps, TFieldPropKey>;
17```
18β
19Defined in: [packages/react-form/src/AppForm/getFormHookHelpers.public.ts:147](https://github.com/TanStack/form/blob/main/packages/react-form/src/AppForm/getFormHookHelpers.public.ts#L147)
20β
21Wraps a component for fields whose value type is assignable to the value
22type accepted by its field API prop.
23β
24The returned component omits `fieldPropKey` from its public props and reads
25that field API from the nearest App Form field context. Use this mode for a
26component that intentionally supports a broader range of field values.
27β
28#### Type Parameters
29β
30##### TComponent
31β
32`TComponent` *extends* `AnyFieldComponent`
33β
34Library-managed. Do not specify explicitly.
35β
36##### TProps
37β
38`TProps` = `PropsOf`\<`TComponent`\>
39β
40Library-managed. Do not specify explicitly.
41β
42##### TFieldPropKey
43β
44`TFieldPropKey` *extends* `string` \| `number` \| `symbol` = `FieldValuePropKeys`\<`TProps`\>
45β
46Library-managed. Do not specify explicitly.
47β
48#### Parameters
49β
50##### Component
51β
52`TComponent`
53β
54The component whose field API prop should be injected.
55β
56##### fieldPropKey
57β
58`TFieldPropKey`
59β
60The prop that accepts the current field API.
61β
62#### Returns
63β
64`LooseInjectedFieldComponent`\<`TComponent`, `TProps`, `TFieldPropKey`\>
65β
66#### Example
67β
68```tsx
69import { getFormHookHelpers } from '@tanstack/react-form'
70import type { AnyFieldApi } from '@tanstack/react-form'
71β
72function FieldErrors({ field }: { field: AnyFieldApi }) {
73 return <span>{field.errors.map((error) => error.message).join(', ')}</span>
74}
75β
76const { fieldComponent } = getFormHookHelpers()
77const Errors = fieldComponent.loose(FieldErrors, 'field')
78```
79β
80***
81β
82### strict
83β
84```ts
85strict: <TComponent, TProps, TFieldPropKey>(Component, fieldPropKey) => StrictInjectedFieldComponent<TComponent, TProps, TFieldPropKey>;
86```
87β
88Defined in: [packages/react-form/src/AppForm/getFormHookHelpers.public.ts:110](https://github.com/TanStack/form/blob/main/packages/react-form/src/AppForm/getFormHookHelpers.public.ts#L110)
89β
90Wraps a component for fields whose value type exactly matches the value
91type of its field API prop.
92β
93The returned component omits `fieldPropKey` from its public props and reads
94that field API from the nearest App Form field context. It must be rendered
95beneath an App Form or field-group `Field` or `ArrayField` component.
96β
97#### Type Parameters
98β
99##### TComponent
100β
101`TComponent` *extends* `AnyFieldComponent`
102β
103Library-managed. Do not specify explicitly.
104β
105##### TProps
106β
107`TProps` = `PropsOf`\<`TComponent`\>
108β
109Library-managed. Do not specify explicitly.
110β
111##### TFieldPropKey
112β
113`TFieldPropKey` *extends* `string` \| `number` \| `symbol` = `FieldValuePropKeys`\<`TProps`\>
114β
115Library-managed. Do not specify explicitly.
116β
117#### Parameters
118β
119##### Component
120β
121`TComponent`
122β
123The component whose field API prop should be injected.
124β
125##### fieldPropKey
126β
127`TFieldPropKey`
128β
129The prop that accepts the current field API.
130β
131#### Returns
132β
133`StrictInjectedFieldComponent`\<`TComponent`, `TProps`, `TFieldPropKey`\>
134β
135#### Example
136β
137```tsx
138import { getFormHookHelpers } from '@tanstack/react-form'
139import type { FieldWithValue } from '@tanstack/react-form'
140β
141function TextInput({
142 field,
143 label,
144}: {
145 field: FieldWithValue<string>
146 label: string
147}) {
148 return (
149 <label>
150 {label}
151 <input
152 value={field.value}
153 onChange={(event) => field.handleChange(event.target.value)}
154 />
155 </label>
156 )
157}
158β
159const { fieldComponent } = getFormHookHelpers()
160const TextField = fieldComponent.strict(TextInput, 'field')
161```