11import * as React from 'react'
22//
33import { useStore } from '@tanstack/react-store'
4- import type {
5- DeepKeys ,
6- DeepValue ,
7- FieldOptions ,
8- FormApi ,
9- } from '@tanstack/form-core'
4+ import type { DeepKeys , DeepValue , FieldOptions } from '@tanstack/form-core'
105import { FieldApi } from '@tanstack/form-core'
116import { useFormContext } from './formContext'
7+ import type { FormFactory } from './createFormFactory'
8+
9+ declare module '@tanstack/form-core' {
10+ // eslint-disable-next-line no-shadow
11+ interface FieldOptions < TData , TFormData > {
12+ formFactory ?: FormFactory < TFormData >
13+ }
14+ }
1215
1316export type UseField < TFormData > = < TField extends DeepKeys < TFormData > > (
1417 opts ?: { name : TField } & FieldOptions <
@@ -17,26 +20,19 @@ export type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(
1720 > ,
1821) => FieldApi < DeepValue < TFormData , TField > , TFormData >
1922
20- export function createUseField < TFormData > ( formApi : FormApi < TFormData > ) {
21- const useFormField : UseField < TFormData > = ( opts ) => {
22- return useField ( { ... opts , form : formApi } as any )
23+ export function createUseField < TFormData > ( ) : UseField < TFormData > {
24+ return ( opts ) => {
25+ return useField ( opts as any )
2326 }
24-
25- return useFormField
2627}
2728
2829export function useField < TData , TFormData > (
2930 opts : FieldOptions < TData , TFormData > & {
3031 // selector: (state: FieldApi<TData, TFormData>) => TSelected
3132 } ,
3233) : FieldApi < TData , TFormData > {
33- // invariant( // TODO:
34- // opts.name,
35- // `useField: A field is required to use this hook. eg, useField('myField', options)`
36- // )
37-
3834 // Get the form API either manually or from context
39- const formApi = useFormContext ( opts . form )
35+ const formApi = useFormContext ( )
4036
4137 const [ fieldApi ] = React . useState < FieldApi < TData , TFormData > > (
4238 ( ) => new FieldApi ( { ...opts , form : formApi } ) ,
0 commit comments