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 spoosh = 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
useRead((api) => api("settings").GET(), {
refetch: { onFocus: false },
});
// Enable reconnect refetch only
useRead((api) => api("user").GET(), {
refetch: {
onFocus: false,
onReconnect: 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
Pass options via the refetch object:
| Option | Type | Description |
|---|---|---|
onFocus | boolean | Override focus refetch behavior |
onReconnect | boolean | Override reconnect refetch behavior |