import type { IContainer } from 'bottlejs'; import type { FC } from 'react'; import { useMemo } from 'react'; export type FCWithDeps = FC & Partial; export function useDependencies(obj: Deps): Omit, keyof FC> { return useMemo(() => obj as Omit, keyof FC>, [obj]); } export function componentFactory, keyof FC>>( Component: CompType, deps: ReadonlyArray, ) { return (container: IContainer, console = globalThis.console) => { deps.forEach((dep) => { const resolvedDependency = container[dep as string]; if (!resolvedDependency && process.env.NODE_ENV !== 'production') { console.error(`[Debug] Could not find "${dep as string}" dependency in container`); } Component[dep] = resolvedDependency; }); return Component; }; }