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