gitscope
← marzneshin / v0.5.2 / dashboard/src/features/entity-table/contexts/entity-table-provider.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/features/entity-table/contexts/entity-table-provider.ts · TypeScript
Blame Raw
 1import { createContext, useContext } from "react";
 2import { UseFilteringReturn } from "../hooks";
 3import { Table } from "@tanstack/react-table";
 4
 5interface EntityTableContextProps<TData> {
 6    table: Table<TData>
 7    data: TData[]
 8    filtering: UseFilteringReturn
 9    isLoading: boolean
10}
11
12export const EntityTableContext = createContext<EntityTableContextProps<any> | null>(null);
13
14export const useEntityTableContext = () => {
15    const ctx = useContext(EntityTableContext);
16    if (!ctx)
17        throw new Error('EntityTable.* component must be rendered as child of EntityTable');
18    return ctx;
19}