import { createContext, ReactNode, useContext } from 'react'; export function createElementContext(errorMessage: string) { const Context = createContext(null); const useElementContext = () => { const context = useContext(Context); if (context === null) { throw new Error(errorMessage); } return context; }; const Provider = ({ children, value }: { value: ContextValue; children: ReactNode }) => ( {children} ); return [Provider, useElementContext] as const; }