Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
22 lines
712 B
TypeScript
22 lines
712 B
TypeScript
// this file is copied from '@calcom/lib/hooks/useCompatSearchParams.tsx'
|
|
import { ReadonlyURLSearchParams, useParams, useSearchParams } from "next/navigation";
|
|
|
|
export const useCompatSearchParams = () => {
|
|
const _searchParams = useSearchParams() ?? new URLSearchParams();
|
|
const params = useParams() ?? {};
|
|
|
|
const searchParams = new URLSearchParams(_searchParams.toString());
|
|
Object.getOwnPropertyNames(params).forEach((key) => {
|
|
searchParams.delete(key);
|
|
|
|
const param = params[key];
|
|
const paramArr = typeof param === "string" ? param.split("/") : param;
|
|
|
|
paramArr?.forEach((p) => {
|
|
searchParams.append(key, p);
|
|
});
|
|
});
|
|
|
|
return new ReadonlyURLSearchParams(searchParams);
|
|
};
|