rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
48 lines (47 loc) • 2.23 kB
TypeScript
import React from "react";
import { type NavigationSnapshot } from "./navigationState.js";
import type { RscPayloadMeta } from "./types.js";
export type NavigationSearchParamsWatch = boolean | readonly string[];
export interface NavigationPendingWatch {
/** Watch pathname changes. Defaults to true when using a watch config. */
pathname?: boolean;
/** Watch all search params, no search params, or a specific list of params. */
searchParams?: NavigationSearchParamsWatch;
/** Watch hash changes. Defaults to false when using a watch config. */
hash?: boolean;
}
export interface NavigationPendingWhenArgs {
currentUrl: URL;
pendingUrl: URL;
}
export interface NavigationPendingOptions {
/** Shorthand for watching only these search params. */
searchParams?: readonly string[];
/** Explicit URL parts to watch. */
watch?: NavigationPendingWatch;
/** Advanced predicate for deciding whether the pending navigation is relevant. */
when?: (args: NavigationPendingWhenArgs) => boolean;
}
export interface NavigationPendingProps extends NavigationPendingOptions {
children?: React.ReactNode;
}
export declare function NavigationPayloadProvider({ children, meta, }: {
children?: React.ReactNode;
meta?: RscPayloadMeta;
}): import("react/jsx-runtime").JSX.Element;
export declare function shouldSuspendForPendingNavigation(snapshot: NavigationSnapshot, options?: NavigationPendingOptions): boolean;
/**
* Suspends while a matching client-side RSC navigation is pending.
*
* Use this hook inside a React <Suspense> boundary. When the pending navigation
* commits to the visible React tree, the thrown promise resolves and React
* retries the render with the newly committed tree.
*/
export declare function useNavigationPending(options?: NavigationPendingOptions): NavigationSnapshot;
/**
* Suspense-aware boundary for client-side RSC navigations.
*
* Wrap server-backed UI with this component inside your own <Suspense> fallback
* to avoid showing stale props while a relevant navigation is in flight.
*/
export declare function NavigationPending({ children, searchParams, watch, when, }: NavigationPendingProps): import("react/jsx-runtime").JSX.Element;