Spoosh
Plugins

Refetch

Refetch on window focus and network reconnect

The refetch plugin automatically refetches queries when the user returns to your app or their network reconnects.

Installation

npm install @spoosh/plugin-refetch

Usage

import { refetchPlugin } from "@spoosh/plugin-refetch";

const plugins = [
  refetchPlugin({
    refetchOnFocus: true,
    refetchOnReconnect: true,
  }),
];

When enabled, queries automatically refetch:

  • When the browser tab regains focus
  • When the network comes back online

Per-Request Override

// Disable focus refetch for this query
useRead((api) => api.settings.$get(), { refetchOnFocus: false });

// Enable reconnect refetch only
useRead((api) => api.user.$get(), {
  refetchOnFocus: false,
  refetchOnReconnect: true,
});

Options

Plugin Config

OptionTypeDefaultDescription
refetchOnFocusbooleanfalseRefetch when window regains focus
refetchOnReconnectbooleanfalseRefetch when network reconnects

Per-Request Options

OptionTypeDescription
refetchOnFocusbooleanOverride focus refetch behavior
refetchOnReconnectbooleanOverride reconnect refetch behavior

On this page