# @monarcode/effetch-query/react (https://0758e0c7.effetch-query.pages.dev/docs/reference/react)

`@monarcode/effetch-query/react` exports the provider, the hooks and the boundaries. Import what you use:

```ts
import {
  HydrationBoundary,
  MissingQueryProviderError,
  QueryBoundary,
  QueryFailure,
  QueryProvider,
  useInfiniteQuery,
  useIsFetching,
  useIsMutating,
  useMutation,
  useMutationState,
  useQueries,
  useQuery,
  useQueryClient,
  useQueryState,
  useRefetch,
  useResetQueryFailure,
  useSuspenseInfiniteQuery,
  useSuspenseQuery,
} from "@monarcode/effetch-query/react";
```

Its exports follow, grouped by the guide that covers them. Each one has
the first paragraph of its docs, and what it needs and how it fails; your
editor shows the rest, with an example, when you hover the name.

## Provide the client

Guide: [Provide the client](https://0758e0c7.effetch-query.pages.dev/docs/getting-started#4-show-a-query).

### QueryProvider

Makes a [`QueryClient.QueryClient`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query-client#queryclient) available to the hooks below it. It also provides the client's registry as `@effect/atom-react`'s `RegistryContext`, so atom-react's own hooks (`useAtomValue` and the rest) share the cache. Read the client with [`useQueryClient`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeryclient). The hooks of `@monarcode/effetch-query/react`, and `HydrationBoundary`, throw a [`MissingQueryProviderError`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#missingqueryprovidererror) outside one.

### QueryProviderProps

Props for [`QueryProvider`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#queryprovider) with a client you own: the provider uses it and never disposes it. For a client the provider makes and disposes, see [`OwnedQueryProviderProps`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#ownedqueryproviderprops).

| Prop        | Type        | Description                                                      |
| ----------- | ----------- | ---------------------------------------------------------------- |
| `client`    | `object`    | The client the hooks below use. The provider doesn't dispose it. |
| `make?`     | `undefined` | Only with an owned client: OwnedQueryProviderProps.make.         |
| `resetKey?` | `undefined` | Only with an owned client: OwnedQueryProviderProps.resetKey.     |
| `children?` | `ReactNode` | The tree that uses the client.                                   |

## Sign out and switch accounts

Guide: [Sign out and switch accounts](https://0758e0c7.effetch-query.pages.dev/docs/cache/accounts).

### OwnedQueryProviderProps

Props for [`QueryProvider`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#queryprovider) with a client the provider owns: it makes one with `make`, a new one each time `resetKey` changes, and disposes each when it's replaced or the provider unmounts. Pass the signed-in account's ID as `resetKey`, so no account sees another's cache.

| Prop        | Type        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `make`      | `function`  | Makes the client, on the first render and again when `resetKey` changes. A new function on each render doesn't make a new client, so an inline arrow is fine.                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `resetKey?` | `string`    | The key the client belongs to, such as the signed-in account's ID. Changing it replaces the client with a new one from `make`, and disposes the old one: its cache goes, and its fetches and mutation runs are interrupted. The tree below never renders with the old client again. A `HydrationBoundary` below loads into the new client only what the server dehydrated after the change (the server's dehydration time against the browser's clock), so state the previous account's page sent doesn't reach the new account. Without it, the provider keeps one client until it unmounts. |
| `client?`   | `undefined` | Only with a client you own: QueryProviderProps.client.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `children?` | `ReactNode` | The tree that uses the client.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

## Read a query

Guide: [Read a query](https://0758e0c7.effetch-query.pages.dev/docs/react).

### MissingQueryProviderError

Thrown by [`useQueryClient`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeryclient), the other hooks of `@monarcode/effetch-query/react` and `HydrationBoundary` outside a [`QueryProvider`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#queryprovider).

### useQuery

Reads a query and keeps it up to date while the component is mounted. On mount, and when `query` changes, it refetches the query if it's stale (`refetchOnMount`) or failed (`retryOnMount`), and while mounted it refetches on focus, reconnect and `refetchInterval` as the query's options say.

Pass `null` to read nothing: it returns `AsyncResult.initial()` and fetches nothing (TanStack's `enabled: false`). In a server render it reads only the cache and never starts a fetch, and the mount refetch doesn't run. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### useQueryClient

Returns the [`QueryClient.QueryClient`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query-client#queryclient) of the nearest [`QueryProvider`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#queryprovider), for running Effects from event handlers. Throws a [`MissingQueryProviderError`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#missingqueryprovidererror) outside one.

## Pause screens you can't see

Guide: [Pause screens you can't see](https://0758e0c7.effetch-query.pages.dev/docs/react/pause).

### UseQueryOptions

Options for [`useInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#useinfinitequery), and the base of [`UseQuerySelectOptions`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeryselectoptions), which [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) and [`useQueryState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystate) take.

| Prop            | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `keepPrevious?` | `union` | If true, while the query has no value yet (say, the next page of a family), the hook shows the last success it showed, as a waiting `Success`, instead of `Initial`: TanStack's `placeholderData: keepPreviousData`. A failure is shown as it is, and a `null` query still reads `Initial`. Default: `false`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `paused?`       | `union` | If true, the hook keeps showing what it last showed and stops counting as a use of the query: an invalidation, focus, reconnect or `refetchInterval` doesn't refetch it for this component, nor does the component re-render. What it shows isn't `waiting`, since nothing fetches for it, and a `clear` replaces it with what the cache has. Use it for a screen that stays mounted under another, as React Native's stack navigators keep them. Paused from its first render, it shows what the cache has, without fetching. `useInfiniteQuery`'s page functions still fetch pages when called. A query whose readers are all paused isn't in use, so it's dropped after `gcTime` like any other, though the paused readers still show what they had. When `paused` turns false, the mount policy runs as on a mount: the query refetches if it's stale or failed, unless another reader fetched it meanwhile and it's still fresh. Default: `false`. |

## Select part of a value

Guide: [Select part of a value](https://0758e0c7.effetch-query.pages.dev/docs/react/select).

### UseQuerySelectOptions

Options for [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) and [`useQueryState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystate): those of [`UseQueryOptions`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeryoptions), and `select`.

| Prop            | Type       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `select?`       | `function` | Derives what the component shows from the query's value, such as one field or a count: the hook returns its result instead of the value, and a failure's previous success is selected too. The cache keeps the whole value, so other readers of the query see it unchanged. The component re-renders when the selection changes or a fetch starts or ends (`waiting`), not when the value changes in a way the selection doesn't show: a selection equal to the last one (`Equal.equals`, which compares plain objects and arrays by their contents) keeps the last result, timestamp included. An inline function runs on every render; for a costly selection, pass one defined outside the component or with `useCallback`, which runs only when the query's result changes. If it throws, the hook shows a failure whose cause is the defect, with no earlier value; if it throws on a failure's previous success, the failure shows without one. With `keepPrevious`, the last selection shown is kept. Default: none, the value itself. |
| `keepPrevious?` | `union`    | If true, while the query has no value yet (say, the next page of a family), the hook shows the last success it showed, as a waiting `Success`, instead of `Initial`: TanStack's `placeholderData: keepPreviousData`. A failure is shown as it is, and a `null` query still reads `Initial`. Default: `false`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `paused?`       | `union`    | If true, the hook keeps showing what it last showed and stops counting as a use of the query: an invalidation, focus, reconnect or `refetchInterval` doesn't refetch it for this component, nor does the component re-render. What it shows isn't `waiting`, since nothing fetches for it, and a `clear` replaces it with what the cache has. Use it for a screen that stays mounted under another, as React Native's stack navigators keep them. Paused from its first render, it shows what the cache has, without fetching. `useInfiniteQuery`'s page functions still fetch pages when called. A query whose readers are all paused isn't in use, so it's dropped after `gcTime` like any other, though the paused readers still show what they had. When `paused` turns false, the mount policy runs as on a mount: the query refetches if it's stale or failed, unless another reader fetched it meanwhile and it's still fresh. Default: `false`.                                                                                       |

## Read a query as an object

Guide: [Read a query as an object](https://0758e0c7.effetch-query.pages.dev/docs/react/as-object).

### useQueryState

Reads a query as [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) does, and returns its result as an object of fields: `status`, `data`, `error`, `isFetching`, `isPlaceholder`, `refetch` and more, TanStack Query's shape. It fetches, refetches and takes options as [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) does, `select` and `keepPrevious` included.

Check `status` before reading `data`: it narrows the object ([`UseQueryStateResult`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystateresult)). A failure keeps the last success as `data`, and its `error` is typed; match each error by its `_tag`, or use `result` with `AsyncResult.builder`. The object keeps its identity while nothing in it changes. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### UseQueryStateFailure

What [`useQueryState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystate) returns when the query has failed: its last fetch failed, or a refetch after a success did. A `select` that throws gives one too.

### UseQueryStatePending

What [`useQueryState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystate) returns while the query has no value and no failure: before its first fetch settles, after a `clear`, and for a `null` query.

### UseQueryStateResult

What [`useQueryState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystate) returns: one of three shapes, told apart by `status` (or `isPending`, `isSuccess` and `isFailure`), which narrows `data`, `error` and `cause`.

### UseQueryStateSuccess

What [`useQueryState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequerystate) returns while the query has a value, including while it refetches.

## Read many queries

Guide: [Read many queries](https://0758e0c7.effetch-query.pages.dev/docs/react/many).

### useQueries

Reads a list of queries whose length can change between renders, such as one per selected item, and keeps each up to date as [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) does: it returns their results in the same order, and `Initial` for a `null` entry. Each query gets the mount policy when it joins the list. A query listed twice is read once, and shows in both places.

The component re-renders when one of the results changes. The array keeps its identity while every result in it does, so it can be a dependency of `useMemo`. Combine the results with `AsyncResult.all`. In a server render it reads only the cache and never starts a fetch. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### UseQueriesEntry

What [`useQueries`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeries) returns for one entry of its list: the query's result, typed by the query, or `AsyncResult<never, never>` for `null`. An entry that may be one of several queries is a union of their results.

### UseQueriesOptions

Options for [`useQueries`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeries).

| Prop      | Type    | Description                                                                                                                                               |
| --------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `paused?` | `union` | If true, the hook keeps showing what it last showed and stops counting as a use of the queries, as UseQueryOptions.paused does for one. Default: `false`. |

### UseQueriesResult

What [`useQueries`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequeries) returns: a result per query, in the same order, as a tuple for a tuple of queries and an array for an array.

## Suspense and error boundaries

Guide: [Suspense and error boundaries](https://0758e0c7.effetch-query.pages.dev/docs/react/suspense).

### QueryBoundary

Shows `pending` while the queries below suspend, and `failure` when one of them fails with nothing to show: a `Suspense` boundary inside an error boundary that catches only `QueryFailure`s. Its `retry` refetches the failed query and renders the children again. Any other error goes on to the next error boundary up.

Use it around components that read with `useSuspenseQuery` or `useSuspenseInfiniteQuery`. Where a router owns the error boundary (an `errorComponent` or an `ErrorBoundary` route export), use `useResetQueryFailure` there instead. In a server render it shows `pending` for what suspends, as `Suspense` does. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### QueryFailure

Thrown by `useSuspenseQuery` and `useSuspenseInfiniteQuery` (from `@monarcode/effetch-query/react`) to the nearest error boundary when a query fails with no earlier value to show (a failed refetch keeps showing the last success instead), or when a reader's `select` throws. It carries the query, so the boundary can refetch it with `useResetQueryFailure`, and the full `Cause`. Tell it from other errors with `QueryFailure.is`. Code outside React never sees it: there, a query's failure keeps its own error type.

### useResetQueryFailure

Returns a function for an error boundary: given what the boundary caught, it refetches the query inside a `QueryFailure`, so the boundary can render its children again and have them suspend on the refetch. Other errors are ignored. [`useSuspenseQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspensequery) and [`useSuspenseInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspenseinfinitequery) throw the failures it resets. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### useSuspenseQuery

Reads a query through React Suspense: it suspends until the query has a value, then returns its `Success`, which stays `waiting` while it refetches. A stale value is shown and refetched in the background (`refetchOnMount`), but one under a second old isn't, as TanStack does, so the value a component suspended on isn't fetched again as it mounts. While suspended, a component keeps its query in use until the fetch settles, even if React abandons the render.

A failure with no earlier value is thrown to the nearest error boundary as a `QueryFailure`, as it was cached: it's thrown again until something refetches the query, such as [`useResetQueryFailure`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#useresetqueryfailure) in the boundary. A refetch that fails after a success keeps showing that success.

In a server render, unlike [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery), it fetches a query the cache doesn't have and suspends on the fetch, for streaming SSR. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### QueryBoundaryFailureProps

What `QueryBoundaryProps.failure` is called with: the failure a query below the boundary threw, and a way to try again.

| Prop    | Type       | Description                                                                                                                                                                 |
| ------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `error` | `unknown`  | The failure squashed to one value (`Cause.squash`), for display: the query's error, or the defect it died with.                                                             |
| `cause` | `object`   | The cause of the failure: the query's error, a defect, or an interruption.                                                                                                  |
| `retry` | `function` | Refetches the failed query and renders the children again, which show `pending` while the refetch is in progress. Only that query: another failed query below throws again. |

### QueryBoundaryProps

Props for [`QueryBoundary`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#queryboundary).

| Prop        | Type        | Description                                                                                                                                                                                                                        |
| ----------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pending?`  | `ReactNode` | The content to show while a query below suspends: the `Suspense` fallback. Default: nothing.                                                                                                                                       |
| `failure`   | `function`  | Renders what to show when a query below fails with nothing to show, such as an error message and a "Try again" button that calls `retry`. Called only for a `QueryFailure`; any other error goes on to the next error boundary up. |
| `children?` | `ReactNode` | The tree that reads queries, with `useSuspenseQuery` for example.                                                                                                                                                                  |

### UseSuspenseQueryOptions

Options for [`useSuspenseQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspensequery).

| Prop      | Type       | Description                                                                                                                                                                                                                                              |
| --------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `select?` | `function` | Derives what the component shows from the query's value, as UseQuerySelectOptions.select does. If it throws, the defect is thrown to the error boundary as a `QueryFailure`, even after an earlier selection was shown. Default: none, the value itself. |

## Refetch on demand

Guide: [Refetch on demand](https://0758e0c7.effetch-query.pages.dev/docs/react/refetch).

### useRefetch

Refetches queries on demand, such as for pull to refresh, with a flag that is true only while this component's own refetch is in progress, unlike a query's `waiting`, which a background refetch also sets. It refetches the [`Query.Target`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#target)'s queries in use, as [`Query.refetch`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#refetch) does. For a screen made of queries with different keys, pass a [`Query.group`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#group) of them: it's refetching until every one has settled. Throws a `MissingQueryProviderError` outside a `QueryProvider`, and a [`Query.KeyHoldsTargetError`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#keyholdstargeterror) for a key that holds a query, a family or a group, such as `[todos, profile]`: pass a [`Query.group`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#group).

### UseRefetchResult

What [`useRefetch`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#userefetch) returns.

## Load more

Guide: [Load more](https://0758e0c7.effetch-query.pages.dev/docs/queries/infinite#load-more).

### useInfiniteQuery

Reads an [`InfiniteQuery.InfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/infinite-query#infinitequery) as [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) does (the mount policy, focus, reconnect and polling refetch every loaded page), with controls to fetch a page at either end: "load more" buttons and infinite scroll.

A page fetch keeps the loaded pages shown: `result` stays a waiting `Success`, and `isFetchingNextPage` tells it from a refetch of every page. A page that fails makes `result` a `Failure` whose `previousSuccess` still holds the pages. Pass `null` to read nothing. It fetches, and throws, when [`useQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usequery) does.

### useSuspenseInfiniteQuery

Reads an [`InfiniteQuery.InfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/infinite-query#infinitequery) through React Suspense, as [`useSuspenseQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspensequery) does, with the same page controls as [`useInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#useinfinitequery). It suspends only until the first page: later pages load while the loaded ones show, through `isFetchingNextPage`. A page that fails isn't thrown, since there are pages to show; only a failure with no pages before it reaches the error boundary, as a `QueryFailure`. It fetches, and throws, when [`useSuspenseQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspensequery) does.

### InfinitePageControls

The page controls [`useInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#useinfinitequery) and [`useSuspenseInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspenseinfinitequery) return beside the result.

### UseInfiniteQueryResult

What [`useInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#useinfinitequery) returns.

### UseSuspenseInfiniteQueryResult

What [`useSuspenseInfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usesuspenseinfinitequery) returns.

## Run a mutation

Guide: [Run a mutation](https://0758e0c7.effetch-query.pages.dev/docs/mutations/run).

### useMutation

Uses a mutation in this component, with state of its own: two components using one mutation never share a waiting or failed state. A run carries on after the component unmounts, so its `onSuccess` and `invalidates` still happen, though the callbacks given to `run` don't ([`UseMutationRunOptions`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usemutationrunoptions)). The mutation's `concurrent` decides how this component's runs overlap: `false` interrupts the previous one, `"queue"` runs them one at a time, and `"drop"` ignores a run while the one `result` shows is in progress. To show runs any component started, use [`useMutationState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usemutationstate).

Define mutations at module level, with [`Mutation.make`](https://0758e0c7.effetch-query.pages.dev/docs/reference/mutation#make): a new definition on each render starts a new state. Outside React, run one with [`Mutation.run`](https://0758e0c7.effetch-query.pages.dev/docs/reference/mutation#run). Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### UseMutationResult

What [`useMutation`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usemutation) returns.

### UseMutationRunOptions

Callbacks for one run of [`useMutation`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usemutation), which its `run` takes: TanStack's `mutate(variables, { onSuccess, onError, onSettled })`. They're called after the mutation's own callbacks, `invalidates` and the client's hooks, before code awaiting `run` carries on.

| Prop         | Type       | Description                                                    |
| ------------ | ---------- | -------------------------------------------------------------- |
| `onSuccess?` | `function` | Called with the value when the run succeeds.                   |
| `onFailure?` | `function` | Called with the cause when the run fails or dies.              |
| `onSettled?` | `function` | Called with the run's `Exit` after `onSuccess` or `onFailure`. |

## Show activity

Guide: [Show activity](https://0758e0c7.effetch-query.pages.dev/docs/mutations/activity).

### useIsFetching

Counts the queries with a fetch in progress on this client: those the [`Query.Target`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#target) matches, or all of them without one, as [`Query.invalidate`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query#invalidate) matches them. Background refetches count, so it suits an app-wide progress bar. The component re-renders when the count changes.

A server render counts none, and so does the first render while the page hydrates. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### useIsMutating

Counts the mutation runs in progress on this client: those of `mutation`, or of every mutation without one, whichever component or Effect started them. A run counts from when it starts until it settles, and a run `concurrent: "queue"` holds back counts while it waits. The component re-renders when the count changes.

A server render counts none, and so does the first render while the page hydrates. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### useMutationState

Lists the runs of a mutation in progress on this client, oldest first, whichever component or Effect started them: a list can show the items a form elsewhere is still saving. A run is listed from when it starts until it settles, however it ends. A run `concurrent: "queue"` holds back is listed while it waits; one that `concurrent: false` makes wait for the run it replaces to roll back is listed once that's done. The list keeps its identity until the runs change.

A server render lists none, and so does the first render while the page hydrates. Throws a `MissingQueryProviderError` outside a `QueryProvider`.

### UseMutationStateRun

A run of a mutation in progress, as [`useMutationState`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#usemutationstate) lists it.

## Load the cache in the browser

Guide: [Load the cache in the browser](https://0758e0c7.effetch-query.pages.dev/docs/server-rendering/hydrate).

### HydrationBoundary

Loads a cache `QueryClient.dehydrate` sent from the server into the client of the nearest `QueryProvider`, as TanStack's `HydrationBoundary` does, so the tree below shows the server's data without fetching it again. Throws a `MissingQueryProviderError` outside a provider.

### HydrationBoundaryProps

Props for [`HydrationBoundary`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react#hydrationboundary).

| Prop        | Type        | Description                                                                  |
| ----------- | ----------- | ---------------------------------------------------------------------------- |
| `state?`    | `object`    | What `QueryClient.dehydrate` sent from the server. Nothing loads without it. |
| `children?` | `ReactNode` | The tree that reads it.                                                      |

## Related pages

- [Entry points](https://0758e0c7.effetch-query.pages.dev/docs/reference): what each entry point exports.
- [`@monarcode/effetch-query`](https://0758e0c7.effetch-query.pages.dev/docs/reference/core): the core entry point's namespaces and top-level names.
- [`Query`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query): defining queries, keys and targets, and the cache from Effect.
- [`InfiniteQuery`](https://0758e0c7.effetch-query.pages.dev/docs/reference/infinite-query): queries that load a list one page at a time.
- [`Mutation`](https://0758e0c7.effetch-query.pages.dev/docs/reference/mutation): defining and running mutations.
- [`Entity`](https://0758e0c7.effetch-query.pages.dev/docs/reference/entity): records whose every cached copy a write updates.
- [`QueryClient`](https://0758e0c7.effetch-query.pages.dev/docs/reference/query-client): the client, its options and hooks, and server rendering.
- [`Signals`](https://0758e0c7.effetch-query.pages.dev/docs/reference/signals): where a client hears about focus and reconnects.
- [`@monarcode/effetch-query/effetch`](https://0758e0c7.effetch-query.pages.dev/docs/reference/effetch): queries and mutations from Effetch endpoints.
- [`@monarcode/effetch-query/react-native`](https://0758e0c7.effetch-query.pages.dev/docs/reference/react-native): focus and online signals for React Native.
- [`@monarcode/effetch-query/react/tanstack-router`](https://0758e0c7.effetch-query.pages.dev/docs/reference/tanstack-router): connecting a client to TanStack Router and Start.