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