import { Context, createContext, ReactNode, useContext } from 'react'; import { StoreApi, useStore } from 'zustand'; const TableSettingsContext = createContext | null>(null); TableSettingsContext.displayName = 'TableSettingsContext'; export function useTableSettings() { const Context = getContextType(); const context = useContext(Context); if (context === null) { throw new Error('must be nested under TableSettingsProvider'); } return useStore(context); } interface ProviderProps { children: ReactNode; settings: StoreApi; } export function TableSettingsProvider({ children, settings, }: ProviderProps) { const Context = getContextType(); return {children}; } function getContextType() { return TableSettingsContext as unknown as Context>; }