import { Provider } from 'preact'; // @TODO: Try to use react import { createContext, useContext } from 'react'; export const createGenericContext = (): [() => K, Provider] => { const genericContext = createContext(undefined); const useGenericContext = (): K => { const context = useContext(genericContext); if (!context) { throw new Error('useGenericContext must be used within a Provider'); } return context as K; }; return [useGenericContext, genericContext.Provider]; };