@@ -57,6 +57,8 @@ export function useJsonSchemaEditor(
5757) : UseJsonSchemaEditorReturn {
5858 const { rootType = "object" , defaultValue, onChange } = options ;
5959
60+ const hasDefaultValue = defaultValue != null && Object . keys ( defaultValue ) . length > 0 ;
61+
6062 const onChangeRef = useRef ( onChange ) ;
6163 onChangeRef . current = onChange ;
6264
@@ -88,7 +90,7 @@ export function useJsonSchemaEditor(
8890
8991 const form = useForm < FormSchema > ( {
9092 resolver : zodResolver ( formSchema ) as any ,
91- defaultValues : defaultValue ? schemaToForm ( defaultValue ) : getDefaultValues ( initialId ) ,
93+ defaultValues : hasDefaultValue ? schemaToForm ( defaultValue ! ) : getDefaultValues ( initialId ) ,
9294 } ) ;
9395
9496 const { setError, clearErrors, setValue, reset : formReset , getValues } = form ;
@@ -177,11 +179,11 @@ export function useJsonSchemaEditor(
177179 } , [ ajvErrors , clearErrors , setError , getValues ] ) ;
178180
179181 useEffect ( ( ) => {
180- if ( ! defaultValue ) {
182+ if ( ! hasDefaultValue ) {
181183 const id = nanoid ( 6 ) ;
182184 formReset ( getDefaultValues ( id ) ) ;
183185 }
184- } , [ rootType , formReset , defaultValue , getDefaultValues ] ) ;
186+ } , [ rootType , formReset , hasDefaultValue , getDefaultValues ] ) ;
185187
186188 const addField = useCallback ( ( ) => {
187189 const id = nanoid ( 6 ) ;
0 commit comments