import { type DependencyList, type RefObject } from 'react'; /** * Like `useMemo`, but with a cleanup callback for disposable native resources. * * - Value is created synchronously during render (available on first render). * - When deps change, the old value is cleaned up during render and a new one * is created. * - On unmount in production: cleaned up synchronously in effect cleanup. * - On unmount in development: cleanup is deferred via `setTimeout(0)` so that * fast refresh and Strict Mode can cancel it when effects re-run. * * Replaces the common `useMemo` + dispose-in-`useEffect`-cleanup pattern that * breaks on fast refresh (HMR re-runs all effect cleanups, disposing the native * object, but `useMemo` returns the same dead reference): * * ```tsx * // BEFORE — breaks on fast refresh * const property = useMemo(() => instance?.getProperty(path), [instance, path]); * useEffect(() => { * const unsub = property?.addListener(setValue); * return () => { unsub?.(); property?.dispose(); }; * }, [property]); * * // AFTER * const property = useDisposableMemo( * () => instance?.getProperty(path), * (p) => p?.dispose(), * [instance, path] * ); * useEffect(() => { * const unsub = property?.addListener(setValue); * return () => unsub?.(); // only unsubscribe, no dispose * }, [property]); * ``` */ export declare function useDisposableMemo(factory: () => T, cleanup: (value: T) => void, deps: DependencyList, liveRef?: RefObject): T; //# sourceMappingURL=useDisposableMemo.d.ts.map