Skip to content
IC Reactor

QueryFactoryFn

Defined in: react/src/types.ts:596

The function createQueryFactory and createSuspenseQueryFactory return: called with args it returns the query object for them, the same object for the same args, and it also carries QueryFactoryMethods.

const getPost = createQueryFactory(backend, { functionName: "get_post" })
// One post's query object
const { data } = getPost([postId]).useQuery()
// Every post's, whatever its args
await getPost.invalidate()

TArgs

The method’s arguments

TQuery

The query object it returns

QueryFactoryFn(args): TQuery

Defined in: react/src/types.ts:597

The function createQueryFactory and createSuspenseQueryFactory return: called with args it returns the query object for them, the same object for the same args, and it also carries QueryFactoryMethods.

TArgs

TQuery

const getPost = createQueryFactory(backend, { functionName: "get_post" })
// One post's query object
const { data } = getPost([postId]).useQuery()
// Every post's, whatever its args
await getPost.invalidate()

getQueryKey: () => readonly unknown[]

Defined in: react/src/types.ts:562

The key prefix every query of this factory shares, whatever its args: the canister (the config’s callConfig.canisterId, else the reactor’s) and the method, plus the reactor’s transform segment and any agent or effective-target segment the config’s callConfig adds, and for an infinite factory its config queryKey. TanStack Query matches keys by prefix, so the prefix covers every args instance and every infinite page set. Queries of the same method made elsewhere share it too.

readonly unknown[]

const getBalance = createQueryFactory(ledger, {
functionName: "icrc1_balance_of",
})
// Every cached balance, whatever the account
ledger.queryClient.getQueriesData({ queryKey: getBalance.getQueryKey() })

QueryFactoryMethods.getQueryKey


invalidate: () => Promise<void>

Defined in: react/src/types.ts:574

Invalidate every query of this factory, whatever its args, on the reactor’s QueryClient. It resolves once the active ones have refetched; a refetch that fails does not reject it.

Promise<void>

// After a transfer, refresh every balance on screen
await getBalance.invalidate()

QueryFactoryMethods.invalidate