fix: hide collections & fields if not exist
This commit is contained in:
parent
f1d7d14145
commit
f2a3cef3cf
@ -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 (
|
||||
<CollectionFieldContext.Provider value={field || getField(field?.name || name)}>
|
||||
<CollectionFieldContext.Provider value={value}>
|
||||
{children}
|
||||
</CollectionFieldContext.Provider>
|
||||
);
|
||||
|
@ -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 <CollectionContext.Provider value={getCollection(collection || name)}>{children}</CollectionContext.Provider>;
|
||||
const value = getCollection(collection || name);
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
return <CollectionContext.Provider value={value}>{children}</CollectionContext.Provider>;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user