Use URLSearchParams

This commit is contained in:
Jip Fr 2023-05-26 23:04:11 +02:00
parent 525f9d0b74
commit 02135527c1

View File

@ -6,14 +6,9 @@ export function useQueryParams() {
const queryParams = useMemo(() => {
// Basic absolutely-not-fool-proof URL query param parser
const obj: Record<string, string | number> = {};
for (const [key, value] of loc.search
.slice(1)
.split("&")
.map((e) => e.split("="))) {
const valueAsNum = Number(value);
obj[key] = Number.isNaN(valueAsNum) ? value : valueAsNum;
}
const obj: Record<string, string> = Object.fromEntries(
new URLSearchParams(loc.search).entries()
);
return obj;
}, [loc]);