From fdb0b1071bc2d7de9d9512a43768d302283c2f80 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Mon, 29 Jan 2024 20:05:42 +0100 Subject: [PATCH] fix: reset paging when clearing filters --- src/lib/sectionList/filters/useSectionListFilters.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib/sectionList/filters/useSectionListFilters.ts b/src/lib/sectionList/filters/useSectionListFilters.ts index 087888b8..3e150da1 100644 --- a/src/lib/sectionList/filters/useSectionListFilters.ts +++ b/src/lib/sectionList/filters/useSectionListFilters.ts @@ -1,9 +1,6 @@ import { useCallback, useMemo } from 'react' import { useQueryParams } from 'use-query-params' -import { - usePaginationQueryParams, - useUpdatePaginationParams, -} from '../usePaginationParams' +import { usePaginationQueryParams } from '../usePaginationParams' import { ParsedFilterParams, filterQueryParamType, @@ -34,9 +31,10 @@ export const useSectionListFilters = () => { const resetParams = Object.fromEntries( validFilterKeys.map((key) => [key, undefined]) ) - return setFilterParams(resetParams) + setFilterParams(resetParams) + } else { + setFilterParams(filter, updateType) } - setFilterParams(filter, updateType) // set page to 1 when filter changes // do this here instead of useEffect to prevent unnecessary refetches setPagingParams((pagingParams) => ({ ...pagingParams, page: 1 }))