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.
Example
Section titled “Example”const getPost = createQueryFactory(backend, { functionName: "get_post" })
// One post's query objectconst { data } = getPost([postId]).useQuery()
// Every post's, whatever its argsawait getPost.invalidate()Extends
Section titled “Extends”Type Parameters
Section titled “Type Parameters”TArgs
The method’s arguments
TQuery
Section titled “TQuery”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.
Parameters
Section titled “Parameters”TArgs
Returns
Section titled “Returns”TQuery
Example
Section titled “Example”const getPost = createQueryFactory(backend, { functionName: "get_post" })
// One post's query objectconst { data } = getPost([postId]).useQuery()
// Every post's, whatever its argsawait getPost.invalidate()Properties
Section titled “Properties”getQueryKey
Section titled “getQueryKey”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.
Returns
Section titled “Returns”readonly unknown[]
Example
Section titled “Example”const getBalance = createQueryFactory(ledger, { functionName: "icrc1_balance_of",})
// Every cached balance, whatever the accountledger.queryClient.getQueriesData({ queryKey: getBalance.getQueryKey() })Inherited from
Section titled “Inherited from”QueryFactoryMethods.getQueryKey
invalidate
Section titled “invalidate”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.
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”// After a transfer, refresh every balance on screenawait getBalance.invalidate()