smolter
API

useRevalidator

Get the active router revalidation function.

Compatibility

ReactAvailable in this renderer's browser integration.
React SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
PreactAvailable in this renderer's browser integration.
Preact SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.

Import from @kasperrt/smolter/react @kasperrt/smolter/preact

Signature

function useRevalidator(): Router["revalidate"];

Parameters

The hook takes no arguments. The returned function accepts RevalidateOptions: route (one route ID/path pattern or an array), reason (manual by default), and optional mutation context. The legacy reason/context arguments remain supported.

Returns

An async function resolving after revalidation.

Usage

Import this API from one of the entry points listed above. Keep server and build helpers in their dedicated subpaths.

const revalidate = useRevalidator();

await revalidate({ route: "/tasks/:id" });
await revalidate({ route: "root" });
await revalidate({ route: ["root", "/tasks/:id"] });

Behavior and edge cases

Without targets, refreshes the active page, loaded fetchers, and registered root/layout data. Targets restrict that set; inactive or unknown routes do not load. shouldRevalidate can skip manual refreshes too. Resolves after selected work finishes. This API returns a function.

View implementation ↗