diff --git a/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form.ts b/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form.ts index e9858d49145bf..66ace3ac3098d 100644 --- a/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form.ts +++ b/src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form.ts @@ -36,22 +36,18 @@ interface UseFormReturn { export function useForm( formConfig?: FormConfig ): UseFormReturn { - const { onSubmit, schema, serializer, deserializer, options, id = 'default' } = formConfig ?? {}; + const { onSubmit, schema, serializer, deserializer, options, id = 'default', defaultValue } = + formConfig ?? {}; const formDefaultValue = useMemo(() => { - if (formConfig === undefined) { + if (defaultValue === undefined || Object.keys(defaultValue).length === 0) { return {}; } - const hasDefaultValue = - formConfig.defaultValue !== undefined && Object.keys(formConfig.defaultValue).length > 0; - - return hasDefaultValue - ? Object.entries(formConfig!.defaultValue as object) - .filter(({ 1: value }) => value !== undefined) - .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}) - : {}; - }, [formConfig]); + return Object.entries(defaultValue as object) + .filter(({ 1: value }) => value !== undefined) + .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}); + }, [defaultValue]); const { errorDisplayDelay, stripEmptyFields: doStripEmptyFields } = options ?? {}; const formOptions = useMemo(