holdReader
Lets a pending read inside a transition keep the boundary's content: when the tracker's hold() returns true (the boundary holds its content for the transition), the reader throws SUSPENSION and keeps its previous value until the boundary wakes it.
Lets a pending read inside a transition keep the boundary's content: when the tracker's hold()
returns true (the boundary holds its content for the transition), the reader throws
SUSPENSION and keeps its previous value until the boundary wakes it. Call it from a data
primitive's reader when its data is pending, the reader is tracked and inTransition is
true, as useResource does. Does nothing before the transition machinery exists, or when the
tracker has no hold.
Import#
ts
import { holdReader } from "@shadow-js/core/extend";
Signature#
ts
function holdReader(tracker: { hold?(): boolean }): void
Parameters#
| Name | Description |
|---|---|
tracker |
The Suspense tracker of the nearest boundary (SuspenseContext). |
Throws#
SUSPENSION(not an error) when the boundary holds its content.
Examples#
ts
import { useContext, SuspenseContext } from "@shadow-js/core";
import { currentListener, holdReader, inTransition } from "@shadow-js/core/extend";
export function readPending(): void {
const tracker = useContext(SuspenseContext);
if (tracker !== null && currentListener() !== null && inTransition()) holdReader(tracker);
}