import { createContext, memo, useContext } from "react"; const contextFactory = ( useContextState: () => T, ContextComponent?: JSX.Element ): { Provider: React.MemoExoticComponent; useContext: () => T; } => { const Context = createContext(Object.create(null) as T); return { Provider: memo(({ children }) => ( {children} {ContextComponent} )), useContext: () => useContext(Context), }; }; export default contextFactory;