@@ -36,7 +36,6 @@ const useAJVForm = <T extends Record<string, any>>(
36
36
[ options ?. debug ] ,
37
37
) ;
38
38
39
- // Precompute field dependencies
40
39
const fieldDependencies = useMemo ( ( ) => {
41
40
const dependencies : Record < string , string [ ] > = { } ;
42
41
if ( schema . allOf ) {
@@ -92,6 +91,7 @@ const useAJVForm = <T extends Record<string, any>>(
92
91
: getErrors ( errors , options ?. userDefinedMessages , logger , schema ) ;
93
92
94
93
const error = fieldErrors [ fieldName as string ] || '' ;
94
+
95
95
setState ( ( prevState ) => ( {
96
96
...prevState ,
97
97
[ fieldName ] : {
@@ -121,8 +121,8 @@ const useAJVForm = <T extends Record<string, any>>(
121
121
} , { } as T ) ;
122
122
123
123
logger . log ( 'Validating entire form:' , { data } ) ;
124
- const isValid = AJVValidate ( data ) ;
125
124
125
+ const isValid = AJVValidate ( data ) ;
126
126
if ( ! isValid && AJVValidate . errors ) {
127
127
logger . error ( 'Form validation failed with errors:' , AJVValidate . errors ) ;
128
128
@@ -131,6 +131,7 @@ const useAJVForm = <T extends Record<string, any>>(
131
131
options ?. userDefinedMessages ,
132
132
logger ,
133
133
) ;
134
+
134
135
setState ( ( prevState ) =>
135
136
Object . keys ( prevState ) . reduce ( ( updatedState , fieldName ) => {
136
137
return {
@@ -146,7 +147,6 @@ const useAJVForm = <T extends Record<string, any>>(
146
147
return { isValid : false , data : null } ;
147
148
}
148
149
149
- // Clear errors if valid
150
150
setState ( ( prevState ) =>
151
151
Object . keys ( prevState ) . reduce ( ( updatedState , fieldName ) => {
152
152
return {
@@ -163,24 +163,14 @@ const useAJVForm = <T extends Record<string, any>>(
163
163
return { isValid : true , data } ;
164
164
} ;
165
165
166
- const isDirty = useMemo ( ( ) => {
167
- return Object . keys ( state ) . some (
168
- ( key ) => state [ key ] . value !== initialStateRef . current [ key ] . value ,
169
- ) ;
170
- } , [ state ] ) ;
171
-
172
- const isValid = useMemo (
173
- ( ) => Object . keys ( state ) . every ( ( key ) => ! state [ key ] . error ) ,
174
- [ state ] ,
175
- ) ;
176
-
177
166
const setErrors = ( errors : ErrorObject [ ] ) => {
178
167
const newErrors = getErrors (
179
168
errors ,
180
169
options ?. userDefinedMessages ,
181
170
logger ,
182
171
schema ,
183
172
) ;
173
+
184
174
setState ( ( prevState ) =>
185
175
Object . keys ( newErrors ) . reduce ( ( updatedState , fieldName ) => {
186
176
return {
@@ -194,6 +184,17 @@ const useAJVForm = <T extends Record<string, any>>(
194
184
) ;
195
185
} ;
196
186
187
+ const isDirty = useMemo ( ( ) => {
188
+ return Object . keys ( state ) . some (
189
+ ( key ) => state [ key ] . value !== initialStateRef . current [ key ] . value ,
190
+ ) ;
191
+ } , [ state ] ) ;
192
+
193
+ const isValid = useMemo (
194
+ ( ) => Object . keys ( state ) . every ( ( key ) => ! state [ key ] . error ) ,
195
+ [ state ] ,
196
+ ) ;
197
+
197
198
useEffect ( ( ) => {
198
199
if (
199
200
! debouncedField ||
0 commit comments