11import { useEffect , useMemo , useRef , useState } from 'react' ;
22import { addUserDefinedKeywords , getErrors , getInitial , getValue } from './utils' ;
3- import { ajv } from './utils/validation' ;
3+ import { ajv as ajvInternal } from './utils/validation' ;
44
55import { ErrorObject , JSONSchemaType , KeywordDefinition , SchemaObject } from 'ajv' ;
66import { useDebounce } from './Hooks/useDebounce' ;
@@ -17,6 +17,7 @@ const useAJVForm = <T extends Record<string, any>>(
1717 initial : T ,
1818 schema : JSONSchemaType < T > | SchemaObject ,
1919 options ?: {
20+ ajv ?: typeof ajvInternal ;
2021 customKeywords ?: KeywordDefinition [ ] ;
2122 errors ?: ErrorObject [ ] ;
2223 userDefinedMessages ?: Record < string , AJVMessageFunction > ;
@@ -25,6 +26,8 @@ const useAJVForm = <T extends Record<string, any>>(
2526 debug ?: boolean ;
2627 } ,
2728) : UseFormReturn < T > => {
29+ const ajvInstance = options ?. ajv || ajvInternal ;
30+
2831 const initialStateRef = useRef < IState < T > > ( getInitial ( initial ) ) ;
2932
3033 const [ state , setState ] = useState < IState < T > > ( getInitial ( initial ) ) ;
@@ -41,10 +44,10 @@ const useAJVForm = <T extends Record<string, any>>(
4144 ) ;
4245
4346 if ( options ?. customKeywords ?. length ) {
44- addUserDefinedKeywords ( ajv , options . customKeywords ) ;
47+ addUserDefinedKeywords ( ajvInstance , options . customKeywords ) ;
4548 }
4649
47- const AJVValidate = ajv . compile ( schema ) ;
50+ const AJVValidate = ajvInstance . compile ( schema ) ;
4851
4952 const resetForm = ( ) => {
5053 logger . log ( 'Form reset to initial state' ) ;
0 commit comments