MCPcopy
hub / github.com/calcom/cal.diy / useCompatSearchParams

Function useCompatSearchParams

packages/lib/hooks/useCompatSearchParams.ts:5–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import { ReadonlyURLSearchParams, useParams, useSearchParams } from "next/navigation";
4
5export const useCompatSearchParams = () => {
6 const _searchParams = useSearchParams() ?? new URLSearchParams();
7 const params = useParams() ?? {};
8
9 const searchParams = new URLSearchParams(_searchParams.toString());
10 Object.getOwnPropertyNames(params).forEach((key) => {
11 searchParams.delete(key);
12
13 // Though useParams is supposed to return a string/string[] as the key's value but it is found to return undefined as well.
14 // Maybe it happens for pages dir when using optional catch-all routes.
15 const param = params[key] || "";
16 const paramArr = typeof param === "string" ? param.split("/") : param;
17
18 paramArr.forEach((p) => {
19 searchParams.append(key, p);
20 });
21 });
22
23 return new ReadonlyURLSearchParams(searchParams);
24};

Callers 15

useRouterQueryFunction · 0.90
useUrlMatchesCurrentUrlFunction · 0.90
ControlledDialogFunction · 0.90
useEmbedParamsFunction · 0.90
PaymentFormFunction · 0.90
SignupFunction · 0.90
useDefaultRoutingFormFunction · 0.90
LoginFunction · 0.90
VerifyFunction · 0.90
ProviderFunction · 0.90

Calls 2

deleteMethod · 0.65
useSearchParamsFunction · 0.50

Tested by

no test coverage detected