@@ -26,6 +26,7 @@ import {
2626 FormContext ,
2727 PrivateFormContext ,
2828 YupSchema ,
29+ MaybeRefOrLazy ,
2930} from './types' ;
3031import {
3132 normalizeRules ,
@@ -40,6 +41,7 @@ import {
4041 withLatest ,
4142 isEqual ,
4243 isTypedSchema ,
44+ lazyToRef ,
4345} from './utils' ;
4446import { isCallable } from '../../shared' ;
4547import { FieldContextKey , FormContextKey , IS_ABSENT } from './symbols' ;
@@ -77,19 +79,19 @@ export type RuleExpression<TValue> =
7779 * Creates a field composite.
7880 */
7981export function useField < TValue = unknown > (
80- name : MaybeRef < string > ,
82+ path : MaybeRefOrLazy < string > ,
8183 rules ?: MaybeRef < RuleExpression < TValue > > ,
8284 opts ?: Partial < FieldOptions < TValue > >
8385) : FieldContext < TValue > {
8486 if ( hasCheckedAttr ( opts ?. type ) ) {
85- return useCheckboxField ( name , rules , opts ) ;
87+ return useCheckboxField ( path , rules , opts ) ;
8688 }
8789
88- return _useField ( name , rules , opts ) ;
90+ return _useField ( path , rules , opts ) ;
8991}
9092
9193function _useField < TValue = unknown > (
92- name : MaybeRef < string > ,
94+ path : MaybeRefOrLazy < string > ,
9395 rules ?: MaybeRef < RuleExpression < TValue > > ,
9496 opts ?: Partial < FieldOptions < TValue > >
9597) : FieldContext < TValue > {
@@ -107,10 +109,11 @@ function _useField<TValue = unknown>(
107109 modelPropName,
108110 syncVModel,
109111 form : controlForm ,
110- } = normalizeOptions ( unref ( name ) , opts ) ;
112+ } = normalizeOptions ( opts ) ;
111113
112114 const injectedForm = controlled ? injectWithSelf ( FormContextKey ) : undefined ;
113115 const form = ( controlForm as PrivateFormContext | undefined ) || injectedForm ;
116+ const name = lazyToRef ( path ) ;
114117
115118 // a flag indicating if the field is about to be removed/unmounted.
116119 let markedForRemoval = false ;
@@ -402,7 +405,7 @@ function _useField<TValue = unknown>(
402405/**
403406 * Normalizes partial field options to include the full options
404407 */
405- function normalizeOptions < TValue > ( name : string , opts : Partial < FieldOptions < TValue > > | undefined ) : FieldOptions < TValue > {
408+ function normalizeOptions < TValue > ( opts : Partial < FieldOptions < TValue > > | undefined ) : FieldOptions < TValue > {
406409 const defaults = ( ) : Partial < FieldOptions < TValue > > => ( {
407410 initialValue : undefined ,
408411 validateOnMount : false ,
@@ -455,7 +458,7 @@ export function extractRuleFromSchema<TValue>(
455458}
456459
457460function useCheckboxField < TValue = unknown > (
458- name : MaybeRef < string > ,
461+ name : MaybeRefOrLazy < string > ,
459462 rules ?: MaybeRef < RuleExpression < TValue > > ,
460463 opts ?: Partial < FieldOptions < TValue > >
461464) : FieldContext < TValue > {
0 commit comments