Skip to content

Commit 7b64244

Browse files
author
Harry Whorlow
committed
feat(react): UseFormReturnType utility type
1 parent 60594af commit 7b64244

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

docs/framework/react/guides/reusable-fields.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ import { useForm, Validator, InferValidFormKeys } from '@tanstack/react-form';
6262

6363
export default function GenericTextField<
6464
TForm,
65+
TFormValidator
6566
TName extends InferValidFormKeys<TForm, string>,
66-
TFormValidator extends Validator<TForm, unknown> | undefined,
6767
>({ name, form }: {
6868
name: TName;
69-
form: ReturnType<typeof useForm<TForm, TFormValidator>
69+
form: UseFormReturnType<TForm, TFormValidator>
7070
> }): JSX.Element {
7171
return (
7272
<form.Field name={name}>

packages/react-form/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
Validator,
66
} from '@tanstack/form-core'
77
import type { FunctionComponent } from 'react'
8+
import { useForm } from './useForm'
89

910
/**
1011
* The field options.
@@ -28,3 +29,9 @@ export type UseFieldOptions<
2829
> & {
2930
mode?: 'value' | 'array'
3031
}
32+
33+
export type UseFormReturnType<TForm, TFormValidator> = TFormValidator extends
34+
| Validator<TForm, unknown>
35+
| undefined
36+
? ReturnType<typeof useForm<TForm, TFormValidator>>
37+
: never

0 commit comments

Comments
 (0)