/** * `@nifrajs/web-react/query` - React bindings for the keyed query-cache + mutations: `useQuery`, * `useInfiniteQuery`, `useMutation`, `useQueryClient`, `QueryClientProvider`, and the SSR * `HydrationBoundary` (+ `dehydrate` re-exported). A drop-in for the TanStack Query surface, * backed by `@nifrajs/web`'s agnostic engine. Imports only `react` + `@nifrajs/web` (never `react-dom/*`), * so route components use it on the server *and* client. No JSX (the package builds with plain `tsc`). * * Resolution order for the client a hook uses: a `QueryClientProvider` in the tree (required for SSR * dehydrate/hydrate and for tests), else a lazily-created **client-side** module singleton (the simple * client-only app - the `typeof window` guard means the server has none, so hooks render idle/pending * and the first client render matches for a clean hydration). */ import type { DehydratedState, InfiniteData, InfiniteQueryOptions, MutationCallbacks, MutationState, QueryClient, QueryOptions, QueryState } from "@nifrajs/web"; import { type ReactNode } from "react"; export type { DehydratedState }; /** Provide a {@link QueryClient} to the tree - required for SSR dehydrate/hydrate and for tests; a * client-only app can omit it and rely on the built-in client-side singleton. */ export declare function QueryClientProvider(props: { readonly client: QueryClient; readonly children?: ReactNode; }): ReactNode; /** The active {@link QueryClient}: a `QueryClientProvider`'s client, else the client-side singleton, * else a no-op (server / pre-hydration). Use it to `invalidateQueries`/`setQueryData`/`prefetchQuery`. */ export declare function useQueryClient(): QueryClient; /** Options for {@link useQuery}. */ export interface UseQueryOptions extends QueryOptions { /** When `false`, don't fetch (the query stays idle) - for dependent queries. Default `true`. */ readonly enabled?: boolean; } /** A query's reactive {@link QueryState} plus `isPending` + `refetch`. */ export interface UseQueryResult extends QueryState { /** `status === "pending"` - no data yet (initial load). */ readonly isPending: boolean; /** `status === "error"`. */ readonly isError: boolean; /** `status === "success"`. */ readonly isSuccess: boolean; /** Force a refetch (ignores `staleTime`). */ readonly refetch: () => Promise; } /** * Subscribe to the keyed query for `key`, fetched via `fn`. Returns `{ status, data, error, isFetching, * updatedAt, isPending, isError, isSuccess, refetch }`. Concurrent `useQuery`s with the same key share * one cache entry + one in-flight fetch (dedup). Fetches on mount and when the key changes; `enabled: * false` keeps it idle (dependent queries). SSR-idle unless a `QueryClientProvider` supplies a hydrated * client. */ export declare function useQuery(key: unknown, fn: () => Promise, options?: UseQueryOptions): UseQueryResult; /** A mutation's reactive state + imperative controls (the TanStack `useMutation` shape). */ export interface UseMutationResult extends MutationState { readonly isIdle: boolean; readonly isPending: boolean; readonly isError: boolean; readonly isSuccess: boolean; /** Fire-and-forget: runs the mutation and swallows rejection (read `error`/`isError` for failures). */ readonly mutate: (variables: TVariables) => void; /** Run the mutation and return the promise (rejects on failure) - for `await`. */ readonly mutateAsync: (variables: TVariables) => Promise; /** Reset back to idle. */ readonly reset: () => void; } /** * A mutation hook (create/update/delete). Returns `{ mutate, mutateAsync, data, error, variables, isIdle, * isPending, isError, isSuccess, reset }`. Invalidate affected queries from `onSuccess` via * `useQueryClient().invalidateQueries(...)`. The handle is stable across renders; the latest `fn`/ * callbacks re-bind each render. */ export declare function useMutation(fn: (variables: TVariables) => Promise, callbacks?: MutationCallbacks): UseMutationResult; /** Options for {@link useInfiniteQuery} - the engine's {@link InfiniteQueryOptions} plus `enabled`. */ export interface UseInfiniteQueryOptions extends InfiniteQueryOptions { readonly enabled?: boolean; } /** An infinite query's reactive state + paging controls. */ export interface UseInfiniteQueryResult extends QueryState> { readonly isPending: boolean; readonly isError: boolean; readonly isSuccess: boolean; readonly fetchNextPage: () => Promise>; readonly fetchPreviousPage: () => Promise>; readonly hasNextPage: boolean; readonly hasPreviousPage: boolean; readonly refetch: () => Promise>; } /** * Subscribe to a paged (infinite-scroll) query. Returns the accumulated `data.pages` plus * `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`. Fetches the first page on mount. * SSR-idle unless a `QueryClientProvider` supplies a hydrated client. */ export declare function useInfiniteQuery(key: unknown, fn: (pageParam: P) => Promise, options: UseInfiniteQueryOptions): UseInfiniteQueryResult; /** * Seed the context's {@link QueryClient} from a server {@link dehydrate} snapshot - the SSR data bridge. * Wrap the app (inside `QueryClientProvider`) so server-prefetched queries are in the cache before the * first client render, avoiding a loading flash. Hydration runs during render (idempotent, fresher-wins), * so the data is available synchronously to child `useQuery`s. */ export declare function HydrationBoundary(props: { readonly state: DehydratedState | undefined; readonly children?: ReactNode; }): ReactNode; //# sourceMappingURL=query.d.ts.map