import React, { createContext, useContext } from "react"; import { VirtualTableSelectionStore, SelectedCell } from "./SelectionStore"; export interface VirtualTableSelectionContextProps { selectionStore: VirtualTableSelectionStore; select: (cell: T | undefined) => void; } const SelectionContext = createContext | null>(null); export const VirtualTableSelectionProvider = ({ store, children }: { store: VirtualTableSelectionStore; children: React.ReactNode; }) => { const value = React.useMemo(() => ({ selectionStore: store, select: store.select }), [store]); return ( {children} ); }; export const useVirtualTableSelection = () => { const context = useContext(SelectionContext); if (!context) { throw new Error("useVirtualTableSelection must be used within a VirtualTableSelectionProvider"); } return context as VirtualTableSelectionContextProps; };