import type { ContextType, Dispatch, FC, PropsWithChildren, SVGAttributes, SetStateAction } from 'react'; import { createContext, useCallback, useContext, useState } from 'react'; interface SVGProps { color?: string | string[]; } type SVGIconProps = Omit, 'color'> & SVGProps; type SvgComponent = FC; const PageStoreContext = createContext( {} as { svgComponent: { name: string; component: SvgComponent } | null; dispatchSvgComponent: Dispatch>; svgProps: SVGProps; dispatchSvgProps: (input: Partial) => void; svgElement: HTMLElement | null; dispatchSvgElement: Dispatch>; }, ); type PageStoreType = ContextType; export const usePageStoreContext = () => { return useContext(PageStoreContext); }; export const PageStore: FC = ({ children }) => { const [svgComponent, dispatchSvgComponent] = useState(null); const [svgProps, setSvgProps] = useState({}); const dispatchSvgProps: PageStoreType['dispatchSvgProps'] = useCallback((input) => { setSvgProps((prev) => ({ ...prev, ...input })); }, []); const [svgElement, dispatchSvgElement] = useState(null); return ( {children} ); };