UNPKG

use-push-router

Version:

A custom hook that simplifies modifying the search params in Next.js

34 lines (27 loc) 1.48 kB
import * as next_navigation from 'next/navigation'; import * as next_dist_shared_lib_app_router_context_shared_runtime from 'next/dist/shared/lib/app-router-context.shared-runtime'; type ArgAdd = { [key: string]: string | string[]; }; type ArgRemove = { [key: string]: string | string[] | undefined; }; type ArgSet = { [key: string]: string | string[]; }; type UpdateSearchParamsAdd = Record<'add', ArgAdd>; type UpdateSearchParamsRemove = Record<'remove', ArgRemove>; type UpdateSearchParamsSet = Record<'set', ArgSet>; type UpdateSearchParamsArgs = UpdateSearchParamsSet | UpdateSearchParamsRemove | UpdateSearchParamsAdd; declare const usePushRoute: () => { pushSearchParams: (params: UpdateSearchParamsArgs) => void; router: next_dist_shared_lib_app_router_context_shared_runtime.AppRouterInstance; searchParams: next_navigation.ReadonlyURLSearchParams; }; declare const useModifiableSearchParams: () => { searchParams: next_navigation.ReadonlyURLSearchParams; updateSearchParams: (params: UpdateSearchParamsArgs) => URLSearchParams; }; declare const updateSearchParams: (currentSearchParams: URLSearchParams) => (params: UpdateSearchParamsArgs) => URLSearchParams; declare function urlSearchParamsToObject(searchParams: URLSearchParams): Record<string, string | string[]>; export { type ArgAdd, type ArgRemove, type ArgSet, type UpdateSearchParamsArgs, updateSearchParams, urlSearchParamsToObject, useModifiableSearchParams, usePushRoute };