SuspenseContext
The context through which an asynchronous source finds the nearest <Suspense> boundary.
The context through which an asynchronous source finds the nearest <Suspense> boundary. Each
boundary provides its SuspenseTracker; the value is null outside any boundary. Read it
when building a data primitive that should hold the boundary while it loads, as useResource
does.
Import#
ts
import { SuspenseContext } from "@shadow-js/core";
Signature#
ts
const SuspenseContext: Context<SuspenseTracker | null>
Examples#
ts
import { SuspenseContext, useContext } from "@shadow-js/core";
function useLoadingHold(promise: Promise<unknown>): void {
const tracker = useContext(SuspenseContext); // null outside any <Suspense>
if (tracker === null) return;
tracker.increment(); // the boundary shows its fallback
promise.finally(() => tracker.decrement());
}