Skip to content

Reactor

Defined in: reactor.ts:42

Reactor class for interacting with IC canisters.

This class provides core functionality for:

  • Direct agent calls using agent.call() and agent.query()
  • Query caching with TanStack Query integration
  • Method calls with result unwrapping

A = BaseActor

The actor service type

T extends TransformKey = "candid"

The type transformation to apply (default: candid = raw Candid types)

new Reactor<A, T>(config): Reactor<A, T>

Defined in: reactor.ts:52

ReactorParameters<A>

Reactor<A, T>

readonly _actor: A

Defined in: reactor.ts:44

Phantom type brand for inference - never assigned at runtime


readonly transform: T

Defined in: reactor.ts:45


clientManager: ClientManager

Defined in: reactor.ts:46


name: string

Defined in: reactor.ts:47


canisterId: Principal

Defined in: reactor.ts:48


service: ServiceClass

Defined in: reactor.ts:49


pollingOptions: PollingOptions

Defined in: reactor.ts:50

get queryClient(): QueryClient

Defined in: reactor.ts:399

Get the query client from clientManager. This is the recommended way to access the query client for direct queries.

QueryClient


get agent(): HttpAgent

Defined in: reactor.ts:407

Get the agent from clientManager. This is the recommended way to access the agent for direct calls.

HttpAgent

getServiceInterface(): ServiceClass

Defined in: reactor.ts:86

Get the service interface (IDL.ServiceClass) for this reactor. Useful for introspection and codec generation.

ServiceClass

The service interface


isQueryMethod<M>(methodName): boolean

Defined in: reactor.ts:105

Check if a method is a query method (query or composite_query).

M extends string

M

boolean


generateQueryKey<M>(params): readonly unknown[]

Defined in: reactor.ts:147

M extends string

ReactorQueryParams<A, M, T>

readonly unknown[]


getQueryOptions<M>(params): FetchQueryOptions<ReactorReturnOk<A, M, T>>

Defined in: reactor.ts:167

M extends string

ReactorCallParams<A, M, T>

FetchQueryOptions<ReactorReturnOk<A, M, T>>


invalidateQueries<M>(params?): void

Defined in: reactor.ts:214

Invalidate cached queries for this canister. This will mark matching queries as stale and trigger a refetch for any active queries.

M extends string

Partial<ReactorQueryParams<A, M, T>>

Optional parameters to filter the invalidation

void

// Invalidate all queries for this canister
reactor.invalidateQueries()
// Invalidate only 'getUser' queries
reactor.invalidateQueries({ functionName: 'getUser' })
// Invalidate 'getUser' query for specific user
reactor.invalidateQueries({ functionName: 'getUser', args: ['user-1'] })

callMethod<M>(params): Promise<ReactorReturnOk<A, M, T>>

Defined in: reactor.ts:254

Call a canister method directly using agent.call() or agent.query(). This is the recommended approach for interacting with canisters.

M extends string

Omit<ReactorCallParams<A, M, T>, "queryKey">

Promise<ReactorReturnOk<A, M, T>>

// Query method
const result = await reactor.callMethod({
functionName: 'greet',
args: ['world'],
});
// Update method with options
const result = await reactor.callMethod({
functionName: 'transfer',
args: [{ to: principal, amount: 100n }],
callConfig: { effectiveCanisterId: principal },
});

fetchQuery<M>(params): Promise<ReactorReturnOk<A, M, T>>

Defined in: reactor.ts:308

Fetch data from the canister and cache it using React Query. This method ensures the data is in the cache and returns it.

M extends string

ReactorCallParams<A, M, T>

Promise<ReactorReturnOk<A, M, T>>


getQueryData<M>(params): ReactorReturnOk<A, M, T> | undefined

Defined in: reactor.ts:318

Get the current data from the cache without fetching.

M extends string

ReactorQueryParams<A, M, T>

ReactorReturnOk<A, M, T> | undefined


subnetId(): Promise<Principal>

Defined in: reactor.ts:379

Get the subnet ID for this canister.

Promise<Principal>


subnetState(options): Promise<ReadStateResponse>

Defined in: reactor.ts:386

Get the subnet state for this canister.

ReadStateOptions

Promise<ReadStateResponse>