docs(core): reusable fields & reusable field utility type #1084
Closedharry-whorlow(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/1084/headopened - @@ -28,3 +29,11 @@2829 > & {2930 mode?: 'value' | 'array'3031 }32+33+/**34+ * The return type use useForm with pre-populated generics35+ */36+export type UseFormReturnType<TForm, TFormValidator> = TFormValidator extends37+ | Validator<TForm, unknown>38+ | undefined39+ ? ReturnType<typeof useForm<TForm, TFormValidator>>
- packages/react-form/src/types.ts line 35@@ -28,3 +28,8 @@2828 > & {2929 mode?: 'value' | 'array'3030 }31+32+/**33+ * The return type use useForm with pre-populated generics34+ */35+export type UseFormReturnType<TForm, TFormValidator> = TFormValidator extends
- docs/framework/react/guides/reusable-fields.md line 27@@ -0,0 +7,21 @@7+8+## Basic Usage9+10+To create a reusable fields, you can do the following.11+12+```tsx13+import { InferValidFormKeys, UseFormReturnType } from '@tanstack/react-form';14+15+export default function GenericTextField<16+ TForm,17+ TFormValidator18+({ name, form }: {19+ name: InferValidFormKeys<TForm, string>;20+ form: UseFormReturnType<TForm, TFormValidator>,21+ }): JSX.Element {22+ return (23+ <form.Field name={name}>24+ {({ handleChange, handleBlur, state }) => (25+ <input26+ value={state.value}27+ onChange={(e) => handleChange(e.target.value as any)}
harry-whorlow(GitHub profile, opens in a new tab) changed the title
crutchcorn(GitHub profile, opens in a new tab) closed this
harry-whorlow(GitHub profile, opens in a new tab) changed the title
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit f0df80464039a65d9719353fd10699fbb23729d6.
nx affected --targets=test:sherif,test:knip,tes...nx run-many --target=build --exclude=examples/**☁️ Nx Cloud last updated this comment at
2025-01-06 07:54:10UTC