Untitled
/* Creates react context provider, and a hook consumer for given hook template */ export function makeContext<T>(useValue: () => T): readonly [FC<PropsWithChildren>, () => T] { const Context = createContext<T>({} as T) const provider: FC<PropsWithChildren> = ({ ...props }) => ( <Context.Provider value={useValue()} {...props} /> ) const consumer = () => useContext(Context) return [provider, consumer] }
Leave a Comment