mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 18:41:51 +01:00
Use URLSearchParams
This commit is contained in:
parent
525f9d0b74
commit
02135527c1
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user