createQueryFactory
createQueryFactory<
Service,Transform,Method,Selected>(reactor,config):SkippableQueryFactoryFn<ReactorArgs<Service,Method,Transform>,QueryResult<QueryFnData<Service,Method,Transform>,Selected,QueryError<Service,Method,Transform>>>
Defined in: react/src/createQuery.ts:293
Create a query factory: a function that takes the method’s args and returns the query object for them, the same object for the same args.
The function also has getQueryKey(), the key prefix every query it
returns shares, and invalidate(), which invalidates all of them whatever
their args. Pass the function itself to a mutation’s invalidateQueries to
refresh every instance after the mutation.
It also takes TanStack Query’s skipToken in place of args, for a
component whose args are not known yet, and returns a query with only
useQuery(), which waits without fetching; see
SkippableQueryFactoryFn.
Type Parameters
Section titled “Type Parameters”Service
Section titled “Service”Service
Transform
Section titled “Transform”Transform extends keyof TransformArgsRegistry<unknown>
Method
Section titled “Method”Method extends string = FunctionName<Service>
Selected
Section titled “Selected”Selected = QueryFnData<Service, Method, Transform>
Parameters
Section titled “Parameters”reactor
Section titled “reactor”Reactor<Service, Transform>
config
Section titled “config”QueryFactoryConfig<NoInfer<Service>, Method, Transform, Selected>
Returns
Section titled “Returns”SkippableQueryFactoryFn<ReactorArgs<Service, Method, Transform>, QueryResult<QueryFnData<Service, Method, Transform>, Selected, QueryError<Service, Method, Transform>>>
Example
Section titled “Example”const getBalance = createQueryFactory(ledger, { functionName: "icrc1_balance_of",})
// In a componentconst { data } = getBalance([{ owner, subaccount: [] }]).useQuery()
// In a component whose owner may not be known yetconst { data: maybe } = getBalance( owner ? [{ owner, subaccount: [] }] : skipToken).useQuery()
// Refetch every account's balance after a transferconst transfer = createMutation(ledger, { functionName: "icrc1_transfer", invalidateQueries: [getBalance],})