mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
15 lines
605 B
TypeScript
15 lines
605 B
TypeScript
import React from 'react';
|
|
import { CollectionContext } from './context';
|
|
import { useCollectionManager } from './hooks';
|
|
import { CollectionOptions } from './types';
|
|
|
|
export const CollectionProvider: React.FC<{ allowNull?: boolean; name?: string; collection?: CollectionOptions }> = (props) => {
|
|
const { allowNull, name, collection, children } = props;
|
|
const { getCollection } = useCollectionManager();
|
|
const value = getCollection(collection || name);
|
|
if (!value && !allowNull) {
|
|
return null;
|
|
}
|
|
return <CollectionContext.Provider value={value}>{children}</CollectionContext.Provider>;
|
|
};
|