PendingRpcRequest

type PendingRpcRequest<TResponse> = object;

Pending requests are the result of calling a supported method on a Rpc object. They encapsulate all of the information necessary to make the request without actually making it.

Calling the `send(options)` method on a PendingRpcRequest<TResponse> will trigger the request and return a promise for TResponse.

Calling the `reactiveStore()` method will fire the request and return a ReactiveActionStore compatible with useSyncExternalStore, Svelte stores, and other reactive primitives.

Type Parameters

Type Parameter
TResponse

Methods

reactiveStore()

reactiveStore(): ReactiveActionStore<[], TResponse>;

Synchronously returns a ReactiveActionStore that fires the request on construction and holds its lifecycle state. Compatible with useSyncExternalStore and other reactive primitives that expect a { subscribe, getState } contract. Call dispatch() to re-fire the request (for example after an error), or reset() to abort the in-flight call and return to status: 'idle'.

Returns

ReactiveActionStore<[], TResponse>

Example

const store = rpc.getAccountInfo(address).reactiveStore();
const state = useSyncExternalStore(store.subscribe, store.getState);
if (state.status === 'error') return <ErrorMessage error={state.error} onRetry={store.dispatch} />;
if (state.status === 'running' && !state.data) return <Spinner />;
return <View data={state.data!} />;

send()

send(options?): Promise<TResponse>;

Parameters

ParameterType
options?Readonly<{ abortSignal?: AbortSignal; }>

Returns

Promise<TResponse>

On this page