DisplayReactor
Defined in: display-reactor.ts:77
DisplayReactor provides automatic type transformations between Candid and display-friendly types, plus optional argument validation.
Type Transformations
Section titled “Type Transformations”bigint→string(for JSON/UI display)Principal→string(text representation)[T] | []→T | null(optional unwrapping)- Small blobs → hex strings
Validation (Optional)
Section titled “Validation (Optional)”Register validators to check arguments before canister calls. Validators receive display types (strings), making them perfect for form validation.
Example
Section titled “Example”import { DisplayReactor } from "@ic-reactor/core"
const reactor = new DisplayReactor<_SERVICE>({ clientManager, canisterId: "...", idlFactory,})
// Optional: Add validationreactor.registerValidator("transfer", ([input]) => { if (!input.to) { return { success: false, issues: [{ path: ["to"], message: "Recipient is required" }] } } return { success: true }})
// Call with display typesawait reactor.callMethod({ functionName: "transfer", args: [{ to: "aaaaa-aa", amount: "100" }], // strings!})Extends
Section titled “Extends”Reactor<A,T>
Type Parameters
Section titled “Type Parameters”A = BaseActor
The actor service type
T extends TransformKey = "display"
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DisplayReactor<
A,T>(config):DisplayReactor<A,T>
Defined in: display-reactor.ts:88
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”DisplayReactor<A, T>
Overrides
Section titled “Overrides”Properties
Section titled “Properties”transform
Section titled “transform”
readonlytransform:T
Defined in: display-reactor.ts:81
Overrides
Section titled “Overrides”_actor
Section titled “_actor”
readonly_actor:A
Defined in: reactor.ts:46
Phantom type brand for inference - never assigned at runtime
Inherited from
Section titled “Inherited from”clientManager
Section titled “clientManager”clientManager:
ClientManager
Defined in: reactor.ts:48
Inherited from
Section titled “Inherited from”name:
string
Defined in: reactor.ts:49
Inherited from
Section titled “Inherited from”canisterId
Section titled “canisterId”canisterId:
Principal
Defined in: reactor.ts:50
Inherited from
Section titled “Inherited from”service
Section titled “service”service:
ServiceClass
Defined in: reactor.ts:51
Inherited from
Section titled “Inherited from”pollingOptions
Section titled “pollingOptions”pollingOptions:
PollingOptions
Defined in: reactor.ts:52
Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”getCodec()
Section titled “getCodec()”getCodec<
M>(methodName):ActorMethodCodecs<A,M> |null
Defined in: display-reactor.ts:137
Get a codec for a specific method. Returns the args and result codecs for bidirectional transformation.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
The name of the method
Returns
Section titled “Returns”ActorMethodCodecs<A, M> | null
Object with args and result codecs, or null if not found
registerValidator()
Section titled “registerValidator()”registerValidator<
M>(methodName,validator):void
Defined in: display-reactor.ts:173
Register a validator for a specific method. Validators receive display types (strings for Principal/bigint).
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
The name of the method to validate
validator
Section titled “validator”DisplayValidator<A, M>
The validator function receiving display types
Returns
Section titled “Returns”void
Example
Section titled “Example”// input.to is string, input.amount is stringreactor.registerValidator("transfer", ([input]) => { if (!/^\d+$/.test(input.amount)) { return { success: false, issues: [{ path: ["amount"], message: "Must be a valid number" }] } } return { success: true }})unregisterValidator()
Section titled “unregisterValidator()”unregisterValidator<
M>(methodName):void
Defined in: display-reactor.ts:183
Unregister a validator for a specific method.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
Returns
Section titled “Returns”void
hasValidator()
Section titled “hasValidator()”hasValidator<
M>(methodName):boolean
Defined in: display-reactor.ts:190
Check if a method has a registered validator.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
Returns
Section titled “Returns”boolean
validate()
Section titled “validate()”validate<
M>(methodName,args):Promise<ValidationResult>
Defined in: display-reactor.ts:218
Validate arguments without calling the canister. Arguments are in display format (strings for Principal/bigint). Useful for form validation before submission.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
The name of the method
ReactorArgs<A, M, T>
The display-type arguments to validate
Returns
Section titled “Returns”Promise<ValidationResult>
ValidationResult indicating success or failure
Example
Section titled “Example”// Validate form data before submissionconst result = await reactor.validate("transfer", [{ to: formData.recipient, // string amount: formData.amount, // string}])
if (!result.success) { result.issues.forEach(issue => { form.setError(issue.path[0], issue.message) })}callMethodWithValidation()
Section titled “callMethodWithValidation()”callMethodWithValidation<
M>(params):Promise<ReactorReturnOk<A,M,T>>
Defined in: display-reactor.ts:254
Call a method with async validation support. Use this instead of callMethod() when you have async validators.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”functionName
Section titled “functionName”M
ReactorArgs<A, M, T>
callConfig?
Section titled “callConfig?”CallConfig
Returns
Section titled “Returns”Promise<ReactorReturnOk<A, M, T>>
Example
Section titled “Example”// Async validator (e.g., check if address is blocked)reactor.registerValidator("transfer", async ([input]) => { const isBlocked = await checkBlocklist(input.to) if (isBlocked) { return { success: false, issues: [{ path: ["to"], message: "Address is blocked" }] } } return { success: true }})
await reactor.callMethodWithValidation({ functionName: "transfer", args: [{ to: "...", amount: "100" }],})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()Inherited from
Section titled “Inherited from”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()Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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[]
Inherited from
Section titled “Inherited from”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>>
Inherited from
Section titled “Inherited from”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'] })Inherited from
Section titled “Inherited from”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 },});Inherited from
Section titled “Inherited from”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>>
Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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>
Inherited from
Section titled “Inherited from”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>