import { createContext , FC , memo , PropsWithChildren , useMemo , useContext } from "react" ; import { DependencyManager } from "graphql-ts-client-api" ; export const DependencyManagerProvider = memo ( ( { children , defaultRegisterDependencies = true } ) => { const arr = useMemo < [ DependencyManager , DependencyManagerProviderConfig ] > ( ( ) => { return [ new DependencyManager ( ) , { defaultRegisterDependencies } ] ; } , [ defaultRegisterDependencies ] ) ; return ( < dependencyManagerContext . Provider value = { arr } > { children } < /dependencyManagerContext.Provider>); } ) ; export function useDependencyManager ( ) { const dependencyManager = useContext ( dependencyManagerContext ) [ 0 ] ; if ( dependencyManager === undefined ) { throw new Error ( "'useDependencyManager()' can only be used under <DependencyManagerProvider/>" ) ; } return dependencyManager ; } export interface DependencyManagerProviderConfig { defaultRegisterDependencies : boolean ; } export const dependencyManagerContext = createContext < [ DependencyManager | undefined , DependencyManagerProviderConfig | undefined ] > ( [ undefined , undefined ] ) ;