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
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”A = BaseActor
The actor service type
T extends TransformKey = "candid"
The type transformation to apply (default: candid = raw Candid types)
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Reactor<
A,T>(config):Reactor<A,T>
Defined in: reactor.ts:52
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”Reactor<A, T>
Properties
Section titled “Properties”_actor
Section titled “_actor”
readonly_actor:A
Defined in: reactor.ts:44
Phantom type brand for inference - never assigned at runtime
transform
Section titled “transform”
readonlytransform:T
Defined in: reactor.ts:45
clientManager
Section titled “clientManager”clientManager:
ClientManager
Defined in: reactor.ts:46
name:
string
Defined in: reactor.ts:47
canisterId
Section titled “canisterId”canisterId:
Principal
Defined in: reactor.ts:48
service
Section titled “service”service:
ServiceClass
Defined in: reactor.ts:49
pollingOptions
Section titled “pollingOptions”pollingOptions:
PollingOptions
Defined in: reactor.ts:50
Accessors
Section titled “Accessors”queryClient
Section titled “queryClient”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”QueryClient
Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”HttpAgent
Methods
Section titled “Methods”getServiceInterface()
Section titled “getServiceInterface()”getServiceInterface():
ServiceClass
Defined in: reactor.ts:86
Get the service interface (IDL.ServiceClass) for this reactor. Useful for introspection and codec generation.
Returns
Section titled “Returns”ServiceClass
The service interface
isQueryMethod()
Section titled “isQueryMethod()”isQueryMethod<
M>(methodName):boolean
Defined in: reactor.ts:105
Check if a method is a query method (query or composite_query).
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
Returns
Section titled “Returns”boolean
generateQueryKey()
Section titled “generateQueryKey()”generateQueryKey<
M>(params): readonlyunknown[]
Defined in: reactor.ts:147
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorQueryParams<A, M, T>
Returns
Section titled “Returns”readonly unknown[]
getQueryOptions()
Section titled “getQueryOptions()”getQueryOptions<
M>(params):FetchQueryOptions<ReactorReturnOk<A,M,T>>
Defined in: reactor.ts:167
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorCallParams<A, M, T>
Returns
Section titled “Returns”FetchQueryOptions<ReactorReturnOk<A, M, T>>
invalidateQueries()
Section titled “invalidateQueries()”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.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params?
Section titled “params?”Partial<ReactorQueryParams<A, M, T>>
Optional parameters to filter the invalidation
Returns
Section titled “Returns”void
Example
Section titled “Example”// Invalidate all queries for this canisterreactor.invalidateQueries()
// Invalidate only 'getUser' queriesreactor.invalidateQueries({ functionName: 'getUser' })
// Invalidate 'getUser' query for specific userreactor.invalidateQueries({ functionName: 'getUser', args: ['user-1'] })callMethod()
Section titled “callMethod()”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.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”Omit<ReactorCallParams<A, M, T>, "queryKey">
Returns
Section titled “Returns”Promise<ReactorReturnOk<A, M, T>>
Example
Section titled “Example”// Query methodconst result = await reactor.callMethod({ functionName: 'greet', args: ['world'],});
// Update method with optionsconst result = await reactor.callMethod({ functionName: 'transfer', args: [{ to: principal, amount: 100n }], callConfig: { effectiveCanisterId: principal },});fetchQuery()
Section titled “fetchQuery()”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.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorCallParams<A, M, T>
Returns
Section titled “Returns”Promise<ReactorReturnOk<A, M, T>>
getQueryData()
Section titled “getQueryData()”getQueryData<
M>(params):ReactorReturnOk<A,M,T> |undefined
Defined in: reactor.ts:318
Get the current data from the cache without fetching.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorQueryParams<A, M, T>
Returns
Section titled “Returns”ReactorReturnOk<A, M, T> | undefined
subnetId()
Section titled “subnetId()”subnetId():
Promise<Principal>
Defined in: reactor.ts:379
Get the subnet ID for this canister.
Returns
Section titled “Returns”Promise<Principal>
subnetState()
Section titled “subnetState()”subnetState(
options):Promise<ReadStateResponse>
Defined in: reactor.ts:386
Get the subnet state for this canister.
Parameters
Section titled “Parameters”options
Section titled “options”ReadStateOptions
Returns
Section titled “Returns”Promise<ReadStateResponse>