import React, { createContext, Dispatch, ReactElement, SetStateAction, useMemo, useState, } from 'react'; export type ContextType = | { colorTheme: T; setColors: Dispatch>; } | undefined; export function injectColorThemeProfile( defaultColorValue: T ): [ React.Context>, (props: { children: any }) => ReactElement | null, () => ContextType ] { const ColorThemeContext = createContext>(undefined); const ColorThemeProvider = function (props: { children: any }) { const [colorTheme, setColors] = useState(defaultColorValue); //setting light theme as default const value = useMemo( () => ({ colorTheme, setColors, }), [colorTheme, setColors] ); return ( {props.children} ); }; const useColorTheme = () => React.useContext(ColorThemeContext)!!; return [ColorThemeContext, ColorThemeProvider, useColorTheme]; }