Skip to content

Commit

Permalink
improve parse_search
Browse files Browse the repository at this point in the history
  • Loading branch information
mebtte committed Apr 30, 2024
1 parent 966a3fd commit 1dd6756
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
14 changes: 3 additions & 11 deletions apps/pwa/src/utils/parse_search.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
function parseSearch<Keys extends string>(search?: string) {
const query: {
function parseSearch<Keys extends string>(search: string) {
return Object.fromEntries(new URLSearchParams(search).entries()) as {
[key in Keys]?: string;
} = {};
if (search) {
const s = search.replace(/\?/g, '');
s.split('&').forEach((kv) => {
const [key, value] = kv.split('=');
query[key] = decodeURIComponent(value);
});
}
return query;
};
}

export default parseSearch;
4 changes: 1 addition & 3 deletions apps/pwa/src/utils/use_navigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ function useNavigate() {
replace = false,
}: {
path?: string;
query?: {
[key: string]: number | string | undefined;
};
query?: Record<string, number | string | undefined>;
replace?: boolean;
}) => {
const combineQuery = {
Expand Down

0 comments on commit 1dd6756

Please sign in to comment.