CollectionProvider
Used to provide Collection instance.
Component
CollectionProvider
interface CollectionProviderProps {
name: string;
dataSource?: string;
children?: ReactNode;
}
The component will query data table information from CollectionManager based on name. If not found, it will not render.
dataSource is used to specify the namespace where the data table is located. If not specified, defaults to default namespace.
import { CollectionProvider } from '@tachybase/client';
const MyComponent = () => {
return (
<CollectionProvider name="users">
<div>...</div>
</CollectionProvider>
)
}
Hooks
useCollection()
Used to get the Collection instance passed by CollectionProvider.
const collection = useCollection()
console.log(collection instanceof Collection) // true
console.log(collection);
Use with Mixin:
const collection = useCollection<TestMixin>()
const collection = useCollection<TestMixin & TestMixin2>()
Example