Skip to content
IC Reactor

useReactorQuery

useReactorQuery is a React hook for fetching data from Internet Computer canisters using a Reactor instance. It is the raw version of useActorQuery that requires explicit reactor passing.

import { useReactorQuery } from "@ic-reactor/react"
import { useReactorQuery } from "@ic-reactor/react"
import { backend } from "./reactor"
function UserProfile({ userId }: { userId: string }) {
const { data, isPending, error } = useReactorQuery({
reactor: backend, // 👈 Required
functionName: "get_user",
args: [userId],
})
if (isPending) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return <div>{data?.name}</div>
}
Option Type Description
reactor Reactor<A, T> The Reactor instance to use
functionName string The canister method to call

Same as useActorQuery.

Returns a TanStack Query result object, same as useActorQuery.

import { useReactorQuery } from "@ic-reactor/react"
import { backend } from "./reactor"
function Greeting() {
const { data } = useReactorQuery({
reactor: backend,
functionName: "greet",
args: ["World"],
})
return <span>{data}</span>
}

args takes TanStack Query’s skipToken while the arguments are not known; see useActorQuery:

import { skipToken, useReactorQuery } from "@ic-reactor/react"
import { backend } from "./reactor"
function UserName({ userId }: { userId: string | undefined }) {
const { data } = useReactorQuery({
reactor: backend,
functionName: "get_user",
args: userId ? [userId] : skipToken,
})
return <span>{data?.name}</span>
}

TypeScript infers types from the passed reactor instance:

import { useReactorQuery } from "@ic-reactor/react"
import { backend } from "./reactor"
function User() {
const { data } = useReactorQuery({
reactor: backend,
functionName: "get_user", // ✅ Autocompletes valid methods
args: ["user-123"], // ✅ Type-checked
})
return <span>{data?.name}</span>
}