Keeps a page's active tab in its path, as one more segment, for the profile and search pages.

Functions

f
useTabParam<T extends string>(
base: string,
validTabs: Iterable<T>,
defaultTab: T
): [T | null, (
tab: T,
search?: string
) => void]

Returns the tab the path segment after base names, defaultTab on the bare base, or null when the segment names none of validTabs, for the page to answer as not found; and a setter that navigates to a tab in place of the current history entry, the default tab to the bare base, with the query string search, the current one by default. A segment after the tab's, as the profile's /follow/playlists, is the tab's own business.

Usage

import * as mod from "src/hooks/shared/useTabParam.ts";