Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / react/src/public-api / suspense

Function: suspense() ​

suspense<T>(source): SuspenseResource<T>

Defined in: projects/libraries/streamix/react/src/lib/suspense.ts:37

Adapts a streamix Atom into a Suspense-compatible resource.

This bridges the first emission only: read() suspends until the atom emits once, then returns synchronously from then on. Reading it does not itself trigger a re-render on later emissions — pair it with useIterable in the same component to stay reactive once past the initial suspend.

Type Parameters ​

T ​

T

Parameters ​

source ​

Atom<T>

Returns ​

SuspenseResource<T>

Example ​

tsx
// Created once, e.g. at module scope or in a loader.
const resource = suspense(flow(() => fetchProfile(id)));

function Profile() {
  resource.read(); // suspends until the first value lands
  const profile = useIterable(userProfile); // stays live afterwards
  return <span>{profile.name}</span>;
}

Released under the MIT License.