NarraLeaf

useQueryParams

The useQueryParams hook, which returns the current LayoutRouter query parameters and updates as they change.

Return current query parameters as an object and keep it in sync with LayoutRouter changes.

import { useQueryParams } from "narraleaf-react";

const { tab, theme } = useQueryParams<{ tab?: string; theme?: string }>();

Definition

function useQueryParams<T extends Record<string,string>>(): T;

Internally this hook subscribes to router.onChange so it re-renders on navigation or when query values are modified via router.setQueryParam(s).

See also: usePathname • useParams

On this page