> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/api-references/react/usebatch.md). Agents can also search and read this documentation through its [MCP server](https://docs.zama.org/protocol/~gitbook/mcp).

# useBatch

Query hook that reads one vault batch with its state, its timings, and the actions you can send now.

Query hook that reads one batch: its `state`, its timings, the account's deposit, and the `actions` you can send now. Wraps [`VaultClient.readBatch`](https://docs.zama.org/protocol/sdk/api-references/sdk/vaultclient.md#readbatch).

The query refetches when `nextChangeAt` passes. While the batch waits for a keeper, it polls every 15 seconds. It stops refetching once the batch is finalized or canceled.

## Import

```ts
import { useBatch } from "@zama-fhe/react-sdk/vaults";
```

## Usage

{% tabs %}
{% tab title="BatchRow\.tsx" %}

```tsx
import { useBatch, useClaim, useQuit } from "@zama-fhe/react-sdk/vaults";
import type { BatchRef } from "@zama-fhe/sdk/vaults";
import type { Address } from "viem";

function BatchRow({ batchRef, account }: { batchRef: BatchRef; account: Address }) {
  const { data: batch } = useBatch(batchRef, { account });
  const claim = useClaim();
  const quit = useQuit();

  if (!batch) return <span>Loading…</span>;

  return (
    <div>
      <span>{batch.state}</span>
      {batch.actions.includes("claim") && (
        <button onClick={() => claim.mutate({ ...batchRef, account })}>Claim</button>
      )}
      {batch.actions.includes("quit") && (
        <button onClick={() => quit.mutate(batchRef)}>Cancel</button>
      )}
    </div>
  );
}
```

{% endtab %}
{% endtabs %}

## Parameters

```ts
import { type UseBatchOptions } from "@zama-fhe/react-sdk/vaults";
import { type BatchRef } from "@zama-fhe/sdk/vaults";
```

### batch

`BatchRef | undefined`

The batch to read: `{ chainId, batcher, batchId }`, as returned in the `batches` of [`useDeposit`](https://docs.zama.org/protocol/sdk/api-references/react/usedeposit.md) or [`useRedeem`](https://docs.zama.org/protocol/sdk/api-references/react/useredeem.md). The query is disabled while `undefined`.

***

### options.account

`Address | undefined`

Read this account's encrypted deposit, and list `claim` and `quit` for it. Without it, `actions` only lists `dispatch` and `finalize`.

```tsx
const { data: batch } = useBatch(batchRef, { account: "0xUser" });
```

Passing `refetchInterval` replaces both the refetch on `nextChangeAt` and the polling while the batch waits for a keeper.

## Return Type

```ts
import { type Batch } from "@zama-fhe/sdk/vaults";
```

The `data` property is a [`Batch`](https://docs.zama.org/protocol/sdk/api-references/sdk/vaultclient.md#batch), or `undefined` while loading or disabled. `Batch` is a union keyed on `state`: narrow on it before reading `cancelsAt` or `exchangeRate`. Each action in `actions` maps to [`useClaim`](https://docs.zama.org/protocol/sdk/api-references/react/useclaim.md), [`useQuit`](https://docs.zama.org/protocol/sdk/api-references/react/usequit.md), [`useDispatch`](https://docs.zama.org/protocol/sdk/api-references/react/usedispatch.md) or [`useFinalize`](https://docs.zama.org/protocol/sdk/api-references/react/usefinalize.md).

## Related

* [Building a vault UI](https://docs.zama.org/protocol/sdk/vaults/building-a-ui.md): what to show and offer in each state
* [useClaim](https://docs.zama.org/protocol/sdk/api-references/react/useclaim.md), [useQuit](https://docs.zama.org/protocol/sdk/api-references/react/usequit.md): get the money out


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/protocol/sdk/api-references/react/usebatch.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
