mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
wip: refresh design
This commit is contained in:
21
packages/lib/client-only/hooks/use-update-search-params.ts
Normal file
21
packages/lib/client-only/hooks/use-update-search-params.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
export const useUpdateSearchParams = () => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
return (params: Record<string, string | number | boolean | null | undefined>) => {
|
||||
const nextSearchParams = new URLSearchParams(searchParams?.toString() ?? '');
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value === undefined || value === null) {
|
||||
nextSearchParams.delete(key);
|
||||
} else {
|
||||
nextSearchParams.set(key, String(value));
|
||||
}
|
||||
});
|
||||
|
||||
router.push(`${pathname}?${nextSearchParams.toString()}`);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user