Skip to content

DisplayReactor

Defined in: display-reactor.ts:135

DisplayReactor provides automatic type transformations between Candid and display-friendly types, plus optional argument validation.

  • bigintstring (for JSON/UI display)
  • Principalstring (text representation)
  • [T] | []T | null (optional unwrapping)
  • Small blobs → hex strings

Register validators to check arguments before canister calls. Validators receive display types (strings), making them perfect for form validation.

import { DisplayReactor } from "@ic-reactor/core"
const reactor = new DisplayReactor<_SERVICE>({
clientManager,
canisterId: "...",
idlFactory,
})
// Optional: Add validation
reactor.registerValidator("transfer", ([input]) => {
if (!input.to) {
return {
success: false,
issues: [{ path: ["to"], message: "Recipient is required" }]
}
}
return { success: true }
})
// Call with display types
await reactor.callMethod({
functionName: "transfer",
args: [{ to: "aaaaa-aa", amount: "100" }], // strings!
})

A = BaseActor

The actor service type

new DisplayReactor<A>(config): DisplayReactor<A>

Defined in: display-reactor.ts:143

DisplayReactorParameters<A>

DisplayReactor<A>

Reactor.constructor

readonly transform: "display" = "display"

Defined in: display-reactor.ts:136

Reactor.transform


readonly _actor: A

Defined in: reactor.ts:44

Phantom type brand for inference - never assigned at runtime

Reactor._actor


clientManager: ClientManager

Defined in: reactor.ts:46

Reactor.clientManager


name: string

Defined in: reactor.ts:47

Reactor.name


canisterId: Principal

Defined in: reactor.ts:48

Reactor.canisterId


service: ServiceClass

Defined in: reactor.ts:49

Reactor.service


pollingOptions: PollingOptions

Defined in: reactor.ts:50

Reactor.pollingOptions

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

Reactor.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

Reactor.agent

getCodec<M>(methodName): ActorMethodCodecs<A, M> | null

Defined in: display-reactor.ts:192

Get a codec for a specific method. Returns the args and result codecs for bidirectional transformation.

M extends string

M

The name of the method

ActorMethodCodecs<A, M> | null

Object with args and result codecs, or null if not found


registerValidator<M>(methodName, validator): void

Defined in: display-reactor.ts:228

Register a validator for a specific method. Validators receive display types (strings for Principal/bigint).

M extends string

M

The name of the method to validate

DisplayValidator<A, M>

The validator function receiving display types

void

// input.to is string, input.amount is string
reactor.registerValidator("transfer", ([input]) => {
if (!/^\d+$/.test(input.amount)) {
return {
success: false,
issues: [{ path: ["amount"], message: "Must be a valid number" }]
}
}
return { success: true }
})

unregisterValidator<M>(methodName): void

Defined in: display-reactor.ts:238

Unregister a validator for a specific method.

M extends string

M

void


hasValidator<M>(methodName): boolean

Defined in: display-reactor.ts:245

Check if a method has a registered validator.

M extends string

M

boolean


validate<M>(methodName, args): Promise<ValidationResult>

Defined in: display-reactor.ts:273

Validate arguments without calling the canister. Arguments are in display format (strings for Principal/bigint). Useful for form validation before submission.

M extends string

M

The name of the method

AsDisplayArgs<ActorMethodParameters<A[M]>>

The display-type arguments to validate

Promise<ValidationResult>

ValidationResult indicating success or failure

// Validate form data before submission
const 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<M>(params): Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

Defined in: display-reactor.ts:309

Call a method with async validation support. Use this instead of callMethod() when you have async validators.

M extends string

M

AsDisplayArgs<ActorMethodParameters<A[M]>>

CallConfig

Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

// 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" }],
})

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

Reactor.getServiceInterface


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

Reactor.isQueryMethod


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

Defined in: reactor.ts:147

M extends string

ReactorQueryParams<A, M, "display">

readonly unknown[]

Reactor.generateQueryKey


getQueryOptions<M>(params): FetchQueryOptions<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

Defined in: reactor.ts:167

M extends string

ReactorCallParams<A, M, "display">

FetchQueryOptions<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

Reactor.getQueryOptions


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, "display">>

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'] })

Reactor.invalidateQueries


callMethod<M>(params): Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

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<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

// 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 },
});

Reactor.callMethod


fetchQuery<M>(params): Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

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, "display">

Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>

Reactor.fetchQuery


getQueryData<M>(params): DisplayOf<OkResult<ActorMethodReturnType<A[M]>>> | undefined

Defined in: reactor.ts:318

Get the current data from the cache without fetching.

M extends string

ReactorQueryParams<A, M, "display">

DisplayOf<OkResult<ActorMethodReturnType<A[M]>>> | undefined

Reactor.getQueryData


subnetId(): Promise<Principal>

Defined in: reactor.ts:379

Get the subnet ID for this canister.

Promise<Principal>

Reactor.subnetId


subnetState(options): Promise<ReadStateResponse>

Defined in: reactor.ts:386

Get the subnet state for this canister.

ReadStateOptions

Promise<ReadStateResponse>

Reactor.subnetState