gitscope
← marzneshin / v0.7.3 / dashboard/src/libs/entity-table/contexts/sidebar-entity-table-provider.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/libs/entity-table/contexts/sidebar-entity-table-provider.ts · TypeScript
Blame Raw
 1import { createContext, useContext } from "react";
 2import {
 3    type SidebarEntityCardSectionsProps
 4} from "@marzneshin/libs/entity-table/components";
 5
 6interface SidebarEntityTableContextProps<SData> {
 7    sidebarEntityId?: string;
 8    setSidebarEntityId: (s: string | undefined) => void;
 9    sidebarEntities: SData[];
10    sidebarCardProps: SidebarEntityCardSectionsProps<SData>;
11}
12
13export const SidebarEntityTableContext = createContext<SidebarEntityTableContextProps<any> | null>(null);
14
15export const useSidebarEntityTableContext = () => {
16    const ctx = useContext(SidebarEntityTableContext);
17    if (!ctx)
18        throw new Error('SidebarEntityTable.* component must be rendered as child of SidebarEntityTable');
19    return ctx;
20}