diff --git a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx index 441b5ef4b..b9f551ee7 100644 --- a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx @@ -1,15 +1,18 @@ +import { SchemaKey } from '@formily/react'; import React from 'react'; -import { merge } from '@formily/shared'; +import { CollectionFieldContext } from './context'; import { useCollection } from './hooks'; import { CollectionFieldOptions } from './types'; -import { CollectionFieldContext } from './context'; -import { SchemaKey } from '@formily/react'; export const CollectionFieldProvider: React.FC<{ name?: SchemaKey; field?: CollectionFieldOptions }> = (props) => { const { name, field, children } = props; const { getField } = useCollection(); + const value = field || getField(field?.name || name); + if (!value) { + return null; + } return ( - + {children} ); diff --git a/packages/core/client/src/collection-manager/CollectionProvider.tsx b/packages/core/client/src/collection-manager/CollectionProvider.tsx index 7dce442ca..8b9e8271e 100644 --- a/packages/core/client/src/collection-manager/CollectionProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionProvider.tsx @@ -6,5 +6,9 @@ import { CollectionOptions } from './types'; export const CollectionProvider: React.FC<{ name?: string; collection?: CollectionOptions }> = (props) => { const { name, collection, children } = props; const { getCollection } = useCollectionManager(); - return {children}; + const value = getCollection(collection || name); + if (!value) { + return null; + } + return {children}; };