Reactor
Defined in: reactor.ts:44
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:54
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:46
Phantom type brand for inference - never assigned at runtime
transform
Section titled “transform”
readonlytransform: keyofTransformArgsRegistry<unknown> ="candid"
Defined in: reactor.ts:47
clientManager
Section titled “clientManager”clientManager:
ClientManager
Defined in: reactor.ts:48
name:
string
Defined in: reactor.ts:49
canisterId
Section titled “canisterId”canisterId:
Principal
Defined in: reactor.ts:50
service
Section titled “service”service:
ServiceClass
Defined in: reactor.ts:51
pollingOptions
Section titled “pollingOptions”pollingOptions:
PollingOptions
Defined in: reactor.ts:52
Accessors
Section titled “Accessors”queryClient
Section titled “queryClient”Get Signature
Section titled “Get Signature”get queryClient():
QueryClient
Defined in: reactor.ts:450
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:458
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”setCanisterId()
Section titled “setCanisterId()”setCanisterId(
canisterId):void
Defined in: reactor.ts:104
Set the canister ID for this reactor. Useful for dynamically switching between canisters of the same type (e.g., multiple ICRC tokens).
Parameters
Section titled “Parameters”canisterId
Section titled “canisterId”The new canister ID (as string or Principal)
Returns
Section titled “Returns”void
Example
Section titled “Example”// Switch to a different ledger canisterledgerReactor.setCanisterId("ryjl3-tyaaa-aaaaa-aaaba-cai")
// Then use queries/mutations as normalconst { data } = icrc1NameQuery.useQuery()setCanisterName()
Section titled “setCanisterName()”setCanisterName(
name):void
Defined in: reactor.ts:125
Set the canister name for this reactor. Useful for dynamically switching between canisters of the same type (e.g., multiple ICRC tokens).
Parameters
Section titled “Parameters”string
The new canister name
Returns
Section titled “Returns”void
Example
Section titled “Example”// Switch to a different ledger canisterledgerReactor.setCanisterName("icrc1")
// Then use queries/mutations as normalconst { data } = icrc1NameQuery.useQuery()getServiceInterface()
Section titled “getServiceInterface()”getServiceInterface():
ServiceClass
Defined in: reactor.ts:138
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:157
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:199
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:219
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:246
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:286
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:359
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:369
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:430
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:437
Get the subnet state for this canister.
Parameters
Section titled “Parameters”options
Section titled “options”ReadStateOptions
Returns
Section titled “Returns”Promise<ReadStateResponse>