diff --git a/packages/core/client/src/schema-component/hooks/useFieldComponentOptions.ts b/packages/core/client/src/schema-component/hooks/useFieldComponentOptions.ts index d8aca42a4..a9d943927 100644 --- a/packages/core/client/src/schema-component/hooks/useFieldComponentOptions.ts +++ b/packages/core/client/src/schema-component/hooks/useFieldComponentOptions.ts @@ -1,7 +1,7 @@ -import { useFieldSchema } from "@formily/react"; -import { useMemo } from "react"; -import { useTranslation } from "react-i18next"; -import { useCollectionManager, useCollection } from "../../collection-manager"; +import { useFieldSchema } from '@formily/react'; +import { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; +import { useCollection, useCollectionManager } from '../../collection-manager'; export const useFieldComponentOptions = () => { const { getCollectionJoinField } = useCollectionManager(); @@ -11,11 +11,11 @@ export const useFieldComponentOptions = () => { const { t } = useTranslation(); const fieldComponentOptions = useMemo(() => { - if ( - !['o2o', 'oho', 'obo', 'o2m', 'linkTo', 'm2o', 'm2m'] - .includes(collectionField.interface) - ) + if (!collectionField || !collectionField?.interface) { return; + } + + if (!['o2o', 'oho', 'obo', 'o2m', 'linkTo', 'm2o', 'm2m'].includes(collectionField.interface)) return; switch (collectionField.interface) { case 'o2m': @@ -31,7 +31,7 @@ export const useFieldComponentOptions = () => { return [ { label: t('Record picker'), value: 'CollectionField' }, { label: t('Select'), value: 'AssociationSelect' }, - ] + ]; default: return [ @@ -39,7 +39,6 @@ export const useFieldComponentOptions = () => { { label: t('Subform'), value: 'FormField' }, { label: t('Select'), value: 'AssociationSelect' }, ]; - } }, [t, collectionField?.interface]);