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