import React from 'react'; type CreateCtx = readonly [ () => A, React.ProviderExoticComponent>, ]; // create context with no upfront defaultValue // without having to do undefined check all the time function createCtx(): CreateCtx { const ctx = React.createContext(undefined); function useCtx(): A { const c = React.useContext(ctx); if (!c) { throw new Error('useTheme must be inside a ThemeProvider'); } return c; } return [useCtx, ctx.Provider] as const; } export default createCtx;