mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Use URLSearchParams
This commit is contained in:
parent
525f9d0b74
commit
02135527c1
1 changed files with 3 additions and 8 deletions
|
@ -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 a new issue