Skip to content

Commit

Permalink
Merge pull request #34 from crow-fox/refactor/useURLQueryParams
Browse files Browse the repository at this point in the history
Refactor/use url query params
  • Loading branch information
crow-fox authored May 6, 2024
2 parents 70562d1 + 0af9889 commit 1e99c33
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/_utils/useURLQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export function useURLQueryParams<T extends string>() {
);

const updateQueries = useCallback(
(queries: Queries<T>) => {
(queries: Queries<T>, options: { scroll: boolean } = { scroll: true }) => {
const queryString = createQueryString(searchParams, queries);
router.push(`${pathname}?${queryString}`);
router.push(`${pathname}?${queryString}`, {
scroll: options.scroll,
});
},
[pathname, router, searchParams],
);
Expand All @@ -51,13 +53,15 @@ export function useURLQueryParams<T extends string>() {
);

const deleteQueries = useCallback(
(queryKeys: T[]) => {
(queryKeys: T[], options: { scroll: boolean } = { scroll: true }) => {
// 対象のクエリパラメーターのみ削除
const params = new URLSearchParams(searchParams);
for (const key of queryKeys) {
params.delete(key);
}
router.push(`${pathname}?${params.toString()}`);
router.push(`${pathname}?${params.toString()}`, {
scroll: options.scroll,
});
},
[pathname, router, searchParams],
);
Expand Down

0 comments on commit 1e99c33

Please sign in to comment.