2022-01-10 19:22:21 +08:00
|
|
|
import React from 'react';
|
2022-02-16 22:48:24 +08:00
|
|
|
import { CollectionContext } from './context';
|
2022-01-10 19:22:21 +08:00
|
|
|
import { useCollectionManager } from './hooks';
|
|
|
|
import { CollectionOptions } from './types';
|
|
|
|
|
2022-02-25 23:09:42 +08:00
|
|
|
export const CollectionProvider: React.FC<{ name?: string; collection?: CollectionOptions }> = (props) => {
|
2022-01-10 19:22:21 +08:00
|
|
|
const { name, collection, children } = props;
|
|
|
|
const { get } = useCollectionManager();
|
|
|
|
return (
|
|
|
|
<CollectionContext.Provider value={collection || get(collection?.name || name)}>
|
|
|
|
{children}
|
|
|
|
</CollectionContext.Provider>
|
|
|
|
);
|
|
|
|
};
|