From ea5c69e11b2758df28f881f9110ca5d4a5d41211 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 24 Apr 2021 19:03:35 +0300 Subject: fix: reset filters correctly --- src/hooks/useQuery.ts | 4 ++-- src/lib/ServiceFilters.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/useQuery.ts b/src/hooks/useQuery.ts index e9a00ec..821dfe4 100644 --- a/src/hooks/useQuery.ts +++ b/src/hooks/useQuery.ts @@ -11,8 +11,8 @@ const useQuery = (): UseQuery => { const query = Object.fromEntries(searchParams); const setQuery = (newQuery: Record): void => { - const queryString = new URLSearchParams(newQuery); - history.push({ search: `?${queryString}` }); + const queryString = new URLSearchParams(newQuery).toString(); + history.push({ search: queryString && `?${queryString}` }); }; return { query, setQuery }; diff --git a/src/lib/ServiceFilters.tsx b/src/lib/ServiceFilters.tsx index b3cfae9..a2c645b 100644 --- a/src/lib/ServiceFilters.tsx +++ b/src/lib/ServiceFilters.tsx @@ -44,7 +44,7 @@ const ServiceFilters: React.FC = () => { setQuery(updatedQuery); }; - const resetFilters = () => history.push(service.route); + const resetFilters = () => setQuery({}); return (
-- cgit v1.2.3