gitscope
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/libs/entity-table/contexts/entity-table-provider.tsx · v0.7.4
Source
1 578311c Mrdn 2y ago import { createContext, useContext } from "react";
2 65bbe9d Mardin 2y ago import { UseFiltersReturn, UsePrimaryFilterReturn } from "../hooks";
3 578311c Mrdn 2y ago import { Table } from "@tanstack/react-table";
4 578311c Mrdn 2y ago
5 578311c Mrdn 2y ago interface EntityTableContextProps<TData> {
6 8b82d79 Mardin 1y ago entityKey: string
7 578311c Mrdn 2y ago table: Table<TData>
8 578311c Mrdn 2y ago data: TData[]
9 65bbe9d Mardin 2y ago primaryFilter: UsePrimaryFilterReturn
10 65bbe9d Mardin 2y ago filters: UseFiltersReturn
11 6b38fe9 Mrdn 2y ago isLoading: boolean
12 578311c Mrdn 2y ago }
13 578311c Mrdn 2y ago
14 578311c Mrdn 2y ago export const EntityTableContext = createContext<EntityTableContextProps<any> | null>(null);
15 578311c Mrdn 2y ago
16 578311c Mrdn 2y ago export const useEntityTableContext = () => {
17 578311c Mrdn 2y ago const ctx = useContext(EntityTableContext);
18 578311c Mrdn 2y ago if (!ctx)
19 578311c Mrdn 2y ago throw new Error('EntityTable.* component must be rendered as child of EntityTable');
20 578311c Mrdn 2y ago return ctx;
21 578311c Mrdn 2y ago }