ExtendCollectionsProvider

用于扩展 Collection

组件

  • 类型
interface ExtendCollectionsProviderProps {
  collections: CollectionOptions[]
  children?: ReactNode
}
  • 示例
import { ExtendCollectionsProvider, CollectionOptions } from '@tachybase/client'

const userCollection: CollectionOptions = {
  name: 'users',
  title: '{{t("Users")}}',
  fields: [
    {
      type: 'string',
      name: 'name',
      title: '{{t("Name")}}',
    },
    {
      type: 'string',
      name: 'email',
      title: '{{t("Email")}}',
    },
  ],
}

const MyPlugin = () => {
  return (
    <ExtendCollectionsProvider collections={[userCollection]}>
      <CollectionProvider name="users">
        <ChildComponent />
      </CollectionProvider>
    </ExtendCollectionsProvider>
  )
}

const ChildComponent = () => {
  const collection = useCollection()

  return (
    <div>
      <h1>{collection.name}</h1>
    </div>
  )
}

Hooks

useExtendCollections()

获取扩展的数据表。

import { useExtendCollections } from '@tachybase/client'

const MyComponent = () => {
  const collections = useExtendCollections()

  return (
    <div>
      {collections.map(collection => (
        <div key={collection.name}>{collection.title}</div>
      ))}
    </div>
  )
}