Skip to content
Source
Sign inSign up
TanStack/form

docs(core): reusable fields & reusable field utility type #1084

Closedharry-whorlow(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/1084/headopened

Showing 5 changed files with 115 additions and 0 deletions (loading 2).

x
0 of 5 viewed, 5 left
92 additions and 0 deletionsdocs/framework/react/guides/reusable-fields.mdAdded
View file
@@ -0,0 +1,92 @@
+---
+id: reusable-fields
+title: Creating reusable fields
+---
+​
+As TanStack form is a headless library, we provide you the core building blocks and then give you the freedom to build on top of them. This page introduces the concept of creating reusable field-components for your form, allowing you to create fields that you can reuse throughout your app.
+​
+## Basic Usage
+​
+To create a reusable fields, you can do the following.
+​
+```tsx
+import { InferValidFormKeys, UseFormReturnType } from '@tanstack/react-form';
+​
+export default function GenericTextField<
+ TForm,
+ TFormValidator
+>({ name, form }: {
+ name: InferValidFormKeys<TForm, string>;
+ form: UseFormReturnType<TForm, TFormValidator>,
+> }): JSX.Element {
+ return (
+ <form.Field name={name}>
+ {({ handleChange, handleBlur, state }) => (
+ <input
+ value={state.value}
+ onChange={(e) => handleChange(e.target.value as any)}