Files
2026-08-07 21:39:30 +02:00

22 lines
1.1 KiB
TypeScript

import { disposeSymbol } from "../disposable/index.mjs";
interface Disposable {
[disposeSymbol](): void;
}
/**
* Production variant: lazily creates the instance on first render and stashes
* a single mount/cleanup pair on it under a module-private symbol so render-
* pass allocations stay at zero after the first render. No StrictMode
* detection is needed because StrictMode's double-mount only happens in dev.
* @returns {T} the lazily-created instance.
*/
declare function useDisposableProduction<T extends Disposable>(factory: () => T): T;
/**
* Lazily creates an instance on first render and runs its `[disposeSymbol]`
* once on unmount. The cleanup runs synchronously; in development StrictMode's
* simulated unmount is detected and skipped so the same instance survives the
* double mount. The development variant degrades to production behaviour on
* runtimes that don't replay the double mount (Preact, React 17) because no
* readable StrictEffectsMode bit is found, so no runtime branching is needed.
*/
export declare const useDisposable: typeof useDisposableProduction;
export {};