import { useMemo } from 'react' import type { FactoryOrInstance } from './types.js' export function useOptionalFactory( arg: FactoryOrInstance, deps?: unknown[], ): T { const memoDeps = [...(deps || [])] if (deps == null && typeof arg !== 'function') { memoDeps.push(arg) } return useMemo(() => { return typeof arg === 'function' ? (arg as () => T)() : (arg as T) }, memoDeps) }