Skip to content

Route hooks

The hooks that read the address, a fetcher or loader data, such as useUrlFilters and usePagePending.

API

Functions

FunctionSignatureDoes
useFetcherPromise<D>({ key, busyMessage, }?: { key?: string | undefined; busyMessage?: string | undefined; }): (target: SubmitTarget, options?: FetcherSubmitOptions | undefined) => Promise<...>A fetcher submit that answers a promise: for a toast's Undo or a dialog's perform, which wait for the result. Resolves with the action's data once the fetcher is idle again. One at a time: a second call while one is running is refused with busyMessage.
useUrlDialog(name: string): { value: string | null; href: (value: string | null) => string; close: () => void; onOpenChange: (open: boolean) => void; }A dialog or panel the address opens: ?add=person. A link to href(value) opens it (and works before the page's script runs, where the page shows the same form as a panel); close() takes the parameter off, replacing the history entry and keeping the scroll.
useUrlFilters<K extends string>(names: readonly K[], { keep, fixed, }?: { keep?: readonly string[] | undefined; fixed?: Readonly<Record<string, string>> | undefined; }): UrlFilters<K>A filter kept in the address, so a view can be reloaded or shared: the fields are local state that apply on submit. keep names other parameters the filter leaves in place (a tab); fixed sets parameters every filtered address carries.
usePagePending(pathname?: string | undefined): booleanWhether this page's own data is being read again, not whether the reader is leaving it.
useScrollToHash(frames?: number): voidScrolls to the address's #id once that element is drawn: sections that load after the page do are not there when the browser looks. Tries each frame for about two seconds, then gives up.
useParamChoice<T extends string>(name: string, loaded: T, choices: readonly T[]): [T, (next: T) => void]A choice kept in one search parameter (?by=word) that switches at once: while the navigation to the other choice loads, the pending address's value shows, and the loader's answer confirms it. loaded is the value the loader read; choices[0] is the default.