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