import { Observable, ObservedValueOf } from "rxjs";
/** @public */
export interface UseObservableOptions {
  /**
   * Pause the active store subscription. While `true`, later emissions do not update the component
   * and the last received value (or the resolved `initialValue`) is returned. A disabled hook
   * performs no subscriptions at all.
   */
  disabled?: boolean;
}
/**
 * Subscribe to an observable and return its latest value, with store updates deferred via
 * [`useDeferredValue`](https://react.dev/reference/react/useDeferredValue).
 *
 * Urgent renders keep the previous value while a background render catches up — so children that
 * suspend on the returned value keep showing already-revealed content instead of the nearest
 * Suspense fallback. Mounts, remounts, and `<Activity>` reveals still render the current snapshot
 * synchronously (no initial-value flash once a value has been emitted).
 *
 * `initialValue` is required: it is what renders until the observable emits. Every value is a
 * valid initial value, `undefined` included — pass it explicitly; omitting the argument throws
 * during render. Functions act as initializers, exactly like `useState`: pass `() => value` to
 * compute the initial value lazily, and an initializer returning the function when the initial
 * value should be a function itself. When there is no meaningful initial value, or you want to
 * show fallback UI while the observable is "loading", reach for {@link useObservablePromise} with
 * `use()` and Suspense instead.
 *
 * The observable is never subscribed during render: every render — the first one and every
 * identity change alike — shows `initialValue` (or the shared entry's last emission) and the live
 * subscription starts on commit, keeping subscribe-time side effects out of the render phase. A
 * synchronous emission replaces the `initialValue` right after that commit. Keep the observable's
 * identity stable across renders (`useMemo`, `useState`, module scope) — like
 * `useSyncExternalStore`'s `subscribe`, an observable rebuilt on every render is re-subscribed on
 * every render, and when it synchronously replays a value that differs from the `initialValue`
 * this forces a render loop.
 *
 * The deferral is identity-coherent: unlike a bare `useDeferredValue(useObservable(...))`, the
 * observable identity and its value are deferred as one snapshot, and when the observable identity
 * changes (e.g. it is memoized on a document id that just changed) the hook falls back to the live
 * value — the `initialValue`, or the new observable's last emission when it is already live
 * elsewhere — so the previous identity's value never renders under the new one.
 *
 * On the server this hook never subscribes the observable and renders the resolved `initialValue`
 * — exactly what the client's first paint will show. Prefer {@link useSyncObservable} for
 * controlled inputs or when the value must stay consistent within the same event.
 *
 * @public
 */
export declare function useObservable<ObservableType extends Observable<any>>(observable: ObservableType, initialValue: ObservedValueOf<ObservableType> | (() => ObservedValueOf<ObservableType>), options?: UseObservableOptions): ObservedValueOf<ObservableType>;
/** @public */
export declare function useObservable<ObservableType extends Observable<any>, InitialValue>(observable: ObservableType, initialValue: InitialValue | (() => InitialValue), options?: UseObservableOptions): InitialValue | ObservedValueOf<ObservableType>;
/**
 * A thenable instrumented for React's `use()` / Suspense protocol.
 *
 * React reads `status` / `value` / `reason` synchronously (see
 * `trackUsedThenable` in facebook/react). When `status` is already set,
 * React will not attach its own instrumentation — we own those fields.
 *
 * The protocol needs a thenable, not a `Promise` instance
 * (https://github.com/reactwg/async-react/discussions/3), so this class
 * composes over a plain `Promise` and delegates `then` / `catch` / `finally`
 * to it. Derived promises are therefore plain `Promise`s on every engine.
 * Subclassing `Promise` instead would hand that construction to the engine,
 * and engines without `Symbol.species` (Hermes) build derived promises from
 * `this.constructor` — recursing into this constructor or leaving a
 * half-instrumented instance whose `status` never advances (#626).
 */
/** @public */
type ObservablePromise<T> = Promise<T> & ({
  status: 'pending';
} | {
  status: 'fulfilled';
  value: T;
} | {
  status: 'rejected';
  reason: unknown;
});
/**
 * Default retention (ms) when the hook does not pass `ttl`.
 * Long enough to bridge commit-time subscribe/unsubscribe gaps — StrictMode
 * double effects, suspend → Suspense retry → commit, quick unmount/remount —
 * so they collapse into a single source subscription instead of refetching.
 */
export declare const DEFAULT_HOOK_TTL = 500;
/**
 * Default retention (ms) for `preloadObservablePromise` when `ttl` is omitted.
 * Longer than the hook default so a hover-warmed value survives until click/navigation.
 */
export declare const DEFAULT_PRELOAD_TTL = 5000;
/** @public */
export interface UseObservablePromiseOptions {
  /**
   * When `true`, this component does not start the live store subscription at
   * commit — no data fetching on behalf of this component, and no re-render
   * notifications for later emissions (the returned promise only advances when
   * this component re-renders for other reasons).
   *
   * Like {@link useObservable}'s `disabled`, this fully prevents fetching. The
   * returned promise is the shared cache entry's current promise: it stays
   * pending until another consumer or {@link preloadObservablePromise} starts
   * the source, or this component re-renders with `disabled: false` — at which
   * point the same pending promise resolves.
   */
  disabled?: boolean;
  /**
   * Retention (ms) of the cache entry once it is settled and has no live
   * subscribers: how long a settled value stays reusable by a later mount
   * without refetching, and how long the shared connection lingers before
   * teardown/eviction. The entry adopts the max `ttl` across all of its
   * consumers.
   *
   * Eviction only affects future consumers: components that are still mounted
   * keep their entry pinned, so hiding a `<Activity>` tree longer than `ttl`
   * does not drop the value it rendered.
   *
   * @defaultValue 500
   */
  ttl?: number;
}
/** @public */
export interface PreloadObservablePromiseOptions {
  /**
   * Retention (ms) for the preloaded cache entry when nothing consumes it.
   *
   * @defaultValue 5000
   */
  ttl?: number;
}
/**
 * Subscribe to an observable and return a `use()`-compatible promise that
 * activates Suspense until the first emission, then updates synchronously for
 * later emissions without re-suspending.
 *
 * The returned promise is meant to be passed as a prop to a child component
 * that reads it with React's `use()`, with a `<Suspense>` boundary **between**
 * this component and that child. The boundary placement is load-bearing:
 * mounting renders never subscribe the source — the fetch starts when the
 * component calling this hook commits (or via
 * {@link preloadObservablePromise}) — and a suspended component never
 * commits. Without a boundary in between, the child's suspension propagates
 * to the hook caller itself and the fetch can never start.
 *
 * Swapping to a new observable on a consumer that is already live follows
 * React's canonical refetch pattern: change the observable inside
 * [`startTransition`](https://react.dev/reference/react/use#re-fetching-data-in-client-components)
 * (or behind `useDeferredValue`) and the previous content stays visible while
 * the new data loads — no preload required. A suspended transition render
 * never commits, so for exactly this case the hook starts the new source
 * during that render (the live-swap eager start): only consumers that are
 * already committed and visible — and not `disabled` — qualify, which is
 * what keeps mounts, server rendering, `disabled` consumers, and hidden
 * `<Activity>` pre-renders fully lazy. A transition abandoned after the swap render can
 * therefore have started a fetch nobody consumes — the entry settles and
 * evicts after `ttl`, but bound never-settling sources with RxJS `timeout`
 * just as you would for {@link preloadObservablePromise}.
 *
 * For the same reason, never call `use()` on the promise in the same
 * component that called this hook: the component suspends on its own pending
 * promise before the commit that would start the fetch — wrong usage in the
 * same way as `use()`-ing a promise created during your own render, and
 * intentionally not guarded against.
 *
 * A hidden `<Activity>` tree pre-rendering this hook is fully paused: no
 * fetching happens until it is revealed (effects mount) or something else
 * warms the entry. To pre-render hidden content *with* data, call the hook in
 * a visible parent and pass the promise into the hidden tree, where
 * `use(promise)` lets React suspend/resume the pre-render on its own terms.
 *
 * Client components only. On the server the observable is never subscribed —
 * the promise stays pending, server rendering emits the Suspense fallback,
 * and the fetch starts on the client once the hydrated component commits
 * ({@link preloadObservablePromise} is likewise a no-op on the server).
 * react-rx is not a library for React Server Components or server-only data
 * flows; there, fetch with async/await or RxJS `firstValueFrom` and pass the
 * promise as a prop for `use()`.
 *
 * @public
 */
export declare function useObservablePromise<T>(observable: Observable<T>, options?: UseObservablePromiseOptions): ObservablePromise<T>;
/**
 * Warm the promise cache outside of rendering (e.g. `onMouseEnter`, route
 * loaders). Creates or reuses the cache entry, re-arms its retention window,
 * starts the source subscription immediately, and returns the same
 * {@link ObservablePromise} the hook would return for that observable. Not a
 * hook — callable anywhere.
 *
 * This is the mechanism for starting a fetch before any consumer is live:
 * hover/route preloads, data for `<Activity>` pre-renders, or having a swap
 * target already in flight (or settled) before a transition swaps to it —
 * transitions themselves no longer require it, since a live consumer's swap
 * render starts the new source (see {@link useObservablePromise}), but a
 * preload on hover means the swap can commit with no pending period at all.
 *
 * On the server this is a no-op: it returns an inert, forever-pending promise
 * and neither subscribes the observable nor touches the cache. react-rx never
 * subscribes observables on the server (see {@link useObservablePromise}), so
 * a preload in shared/isomorphic code (e.g. a route loader) only takes effect
 * in the browser.
 *
 * Pending entries are never timed out: a never-emitting source keeps the
 * promise pending and the subscription alive until it settles. Bound hang
 * risk with RxJS `timeout` (or cancel the source) when a preload can stall.
 *
 * @public
 */
export declare function preloadObservablePromise<T>(observable: Observable<T>, options?: PreloadObservablePromiseOptions): ObservablePromise<T>;
/**
 * Creates an observable event stream and a stable handler that pushes events into it.
 *
 * The underlying `Subject` is scoped to the component instance and created once. Only its
 * observable side is exposed, so values can only be pushed through the handler.
 *
 * @public
 */
export declare function useObservableSubject<T>(): [events$: Observable<T>, handleEvent: (event: T) => void];
/**
 * Subscribe to an observable and return its latest value synchronously via
 * [`useSyncExternalStore`](https://react.dev/reference/react/useSyncExternalStore).
 *
 * This is the v4 `useObservable` behavior. Prefer the deferred {@link useObservable} for most
 * reads. Reach for `useSyncObservable` when the value feeds a controlled input, or must stay
 * consistent within the same event.
 *
 * `initialValue` is required: it is what renders until the observable emits, and what the server
 * renders. Every value is a valid initial value, `undefined` included — pass it explicitly;
 * omitting the argument throws during render. Functions act as initializers, exactly like
 * `useState`: pass `() => value` to compute the initial value lazily, and an initializer
 * returning the function when the initial value should be a function itself. When there is no
 * meaningful initial value, or you want to show fallback UI while the observable is "loading",
 * reach for {@link useObservablePromise} with `use()` and Suspense instead.
 *
 * Like {@link useObservable}, the observable is never subscribed during render: every render —
 * the first one and every identity change alike — shows `initialValue` (or the shared entry's
 * last emission) and the live subscription starts on commit. Keep the observable's identity
 * stable across renders (`useMemo`, `useState`, module scope) — like `useSyncExternalStore`'s
 * `subscribe`, an observable rebuilt on every render is re-subscribed on every render, and when
 * it synchronously replays a value that differs from the `initialValue` this forces a render
 * loop.
 *
 * **Caveat:** store mutations cannot be marked as Transitions. Suspending on a value returned by
 * this hook replaces already-visible content with the nearest Suspense fallback — see the
 * [useSyncExternalStore caveats](https://react.dev/reference/react/useSyncExternalStore#caveats).
 *
 * @public
 */
export declare function useSyncObservable<ObservableType extends Observable<any>>(observable: ObservableType, initialValue: ObservedValueOf<ObservableType> | (() => ObservedValueOf<ObservableType>), options?: UseObservableOptions): ObservedValueOf<ObservableType>;
/** @public */
export declare function useSyncObservable<ObservableType extends Observable<any>, InitialValue>(observable: ObservableType, initialValue: InitialValue | (() => InitialValue), options?: UseObservableOptions): InitialValue | ObservedValueOf<ObservableType>;
export type { ObservablePromise };
//# sourceMappingURL=index.d.ts.map