Skip to Content
Effetch Query
Mutations

Show activity

Show a global indicator while queries or mutations run.

A mutation's state belongs to the component that runs it. To show what's saving anywhere in the app, read the client's activity instead.

The examples import toggle-todo.ts from Getting started.

Runs of one mutation. useMutationState lists a mutation's runs in progress, oldest first, with their variables, whichever component or Effect started them:

import {  } from "@monarcode/effetch-query/react";

import {  } from "./toggle-todo.js";

export function () {
  const  = ();

  return . === 0 ? null : (
    < ="status">
      Saving {.(() => `#${...}`).(", ")}
    </>
  );
}

Each entry is a UseMutationStateRun, with the variables the run was started with and its result, a waiting Initial. A run is listed from when it starts until it settles, however it ends. A run "queue" holds back is listed while it waits.

Counts. useIsFetching counts the queries fetching on the provider's client, and useIsMutating the mutation runs in progress. Together they drive an app-wide progress bar:

import { ,  } from "@monarcode/effetch-query/react";

export function () {
  const  = () + () > 0;

  return < ="progressbar" ="Loading" ={!} />;
}

Both count background refetches, and runs that any component or Mutation.run started. Pass a target to count fewer: useIsFetching(["todos"]) counts the todos queries, and useIsMutating(toggleTodo) the runs of one mutation.

A server render counts nothing in progress, and so does the first render as the page hydrates, so the markup matches; the counts show right after. All three hooks throw a MissingQueryProviderError outside a QueryProvider.