import { Context, createContext, ReactNode, useContext, useMemo } from 'react'; interface TableSettingsContextInterface { settings: T; } 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 context; } interface ProviderProps { children: ReactNode; settings: T; } export function TableSettingsProvider({ children, settings, }: ProviderProps) { const Context = getContextType(); const contextValue = useMemo( () => ({ settings, }), [settings] ); return {children}; } function getContextType() { return TableSettingsContext as unknown as Context< TableSettingsContextInterface >; }