CollectionProvider
用于提供 Collection 实例。
组件
CollectionProvider
1interface CollectionProviderProps {
2 name: string;
3 dataSource?: string;
4 children?: ReactNode;
5}
组件会根据 name
去 CollectionManager 中查询数据表信息,如果查询不到,则会不进行渲染。
dataSource
用于指定数据表所在的命名空间,如果不指定,则默认命名空间。
1import { CollectionProvider } from '@tachybase/client';
2
3const MyComponent = () => {
4 return (
5 <CollectionProvider name="users">
6 <div>...</div>
7 </CollectionProvider>
8 )
9}
Hooks
useCollection()
用于获取 CollectionProvider
传递的 Collection
实例。
1const collection = useCollection()
2
3console.log(collection instanceof Collection) // true
4console.log(collection);
结合 Mixin 使用:
1const collection = useCollection<TestMixin>()
2const collection = useCollection<TestMixin & TestMixin2>()
示例