用于扩展 Collection 。
1interface ExtendCollectionsProviderProps {
2 collections: CollectionOptions[]
3 children?: ReactNode
4}
1import { ExtendCollectionsProvider, CollectionOptions } from '@tachybase/client'
2
3const userCollection: CollectionOptions = {
4 name: 'users',
5 title: '{{t("Users")}}',
6 fields: [
7 {
8 type: 'string',
9 name: 'name',
10 title: '{{t("Name")}}',
11 },
12 {
13 type: 'string',
14 name: 'email',
15 title: '{{t("Email")}}',
16 },
17 ],
18}
19
20const MyPlugin = () => {
21 return (
22 <ExtendCollectionsProvider collections={[userCollection]}>
23 <CollectionProvider name="users">
24 <ChildComponent />
25 </CollectionProvider>
26 </ExtendCollectionsProvider>
27 )
28}
29
30const ChildComponent = () => {
31 const collection = useCollection()
32
33 return (
34 <div>
35 <h1>{collection.name}</h1>
36 </div>
37 )
38}
获取扩展的数据表。
1import { useExtendCollections } from '@tachybase/client'
2
3const MyComponent = () => {
4 const collections = useExtendCollections()
5
6 return (
7 <div>
8 {collections.map(collection => (
9 <div key={collection.name}>{collection.title}</div>
10 ))}
11 </div>
12 )
13}