gitscope
← marzneshin / v0.3.0-alpha3 / dashboard/src/components/entity-table/entity-table-provider.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/components/entity-table/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}
10
11export const EntityTableContext = createContext<EntityTableContextProps<any> | null>(null);
12
13export const useEntityTableContext = () => {
14    const ctx = useContext(EntityTableContext);
15    if (!ctx)
16        throw new Error('EntityTable.* component must be rendered as child of EntityTable');
17    return ctx;
18}