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-refetchUsage
import { Spoosh } from "@spoosh/core";
import { refetchPlugin } from "@spoosh/plugin-refetch";
const client = new Spoosh<ApiSchema, Error>("/api").use([
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
injectRead((api) => api("settings").GET(), { refetchOnFocus: false });
// Enable reconnect refetch only
injectRead((api) => api("user").GET(), {
refetchOnFocus: false,
refetchOnReconnect: true,
});Options
Plugin Config
| Option | Type | Default | Description |
|---|---|---|---|
refetchOnFocus | boolean | false | Refetch when window regains focus |
refetchOnReconnect | boolean | false | Refetch when network reconnects |
Per-Request Options
| Option | Type | Description |
|---|---|---|
refetchOnFocus | boolean | Override focus refetch behavior |
refetchOnReconnect | boolean | Override reconnect refetch behavior |