Fix getQueryString

Browsers without size property for URLSearchParams always returned an
empty string.
This commit is contained in:
Matthias Camenzind 2024-06-19 19:39:31 +02:00
parent 1299f7ce07
commit f8513f7311

View file

@ -5,8 +5,9 @@ export default function getQueryString<
Object.entries(obj)
.filter(([, val]) => val !== undefined && val !== null)
.forEach(([key, val]) => searchParams.set(key, val ?? ""));
if (searchParams.size) {
return "?" + searchParams.toString();
const params = searchParams.toString();
if (params) {
return "?" + params;
}
return "";
}