# QueryFactoryFn

Defined in: [react/src/types.ts:596](https://github.com/B3Pay/ic-reactor/blob/f1956947ae037304fce1675a38695964c1aa9e32/packages/react/src/types.ts#L596)

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](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/).

## Example

```typescript
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()
```

## Extends

- [`QueryFactoryMethods`](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/)

## Type Parameters

### TArgs

`TArgs`

The method's arguments

### TQuery

`TQuery`

The query object it returns

> **QueryFactoryFn**(`args`): `TQuery`

Defined in: [react/src/types.ts:597](https://github.com/B3Pay/ic-reactor/blob/f1956947ae037304fce1675a38695964c1aa9e32/packages/react/src/types.ts#L597)

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](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/).

## Parameters

### args

`TArgs`

## Returns

`TQuery`

## Example

```typescript
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()
```

## Properties

### getQueryKey

> **getQueryKey**: () => readonly `unknown`[]

Defined in: [react/src/types.ts:562](https://github.com/B3Pay/ic-reactor/blob/f1956947ae037304fce1675a38695964c1aa9e32/packages/react/src/types.ts#L562)

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

readonly `unknown`[]

#### Example

```typescript
const getBalance = createQueryFactory(ledger, {
  functionName: "icrc1_balance_of",
})

// Every cached balance, whatever the account
ledger.queryClient.getQueriesData({ queryKey: getBalance.getQueryKey() })
```

#### Inherited from

[`QueryFactoryMethods`](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/).[`getQueryKey`](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/#getquerykey)

***

### invalidate

> **invalidate**: () => `Promise`\<`void`\>

Defined in: [react/src/types.ts:574](https://github.com/B3Pay/ic-reactor/blob/f1956947ae037304fce1675a38695964c1aa9e32/packages/react/src/types.ts#L574)

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

`Promise`\<`void`\>

#### Example

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

#### Inherited from

[`QueryFactoryMethods`](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/).[`invalidate`](https://ic-reactor.b3pay.net/v3/libs/interfaces/queryfactorymethods/#invalidate)