Skip to content

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: "getUser",
args: [userId],
})
if (isPending) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return <div>{data?.name}</div>
}
OptionTypeDescription
reactorReactor<A, T>The Reactor instance to use
functionNamestringThe canister method to call

Same as useActorQuery.

Returns a TanStack Query result object, same as useActorQuery.

const { data } = useReactorQuery({
reactor: backend,
functionName: "greet",
args: ["World"],
})

TypeScript infers types from the passed reactor instance:

const { data } = useReactorQuery({
reactor: backend,
functionName: "getUser", // ✅ Autocompletes valid methods
args: ["user-123"], // ✅ Type-checked
})