Skip to content

Commit

Permalink
fix: cache not resetting when pagination was reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ytkimirti committed Nov 18, 2024
1 parent c6b5f57 commit aed0c8d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/databrowser/hooks/use-keys.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { createContext, useCallback, useContext, useMemo, type PropsWithChildren } from "react"
import {
createContext,
useCallback,
useContext,
useMemo,
useRef,
type PropsWithChildren,
} from "react"
import { useDatabrowserStore } from "@/store"
import { useInfiniteQuery, type UseInfiniteQueryResult } from "@tanstack/react-query"

Expand Down Expand Up @@ -27,12 +34,17 @@ export const KeysProvider = ({ children }: PropsWithChildren) => {
)

const { fetchKeys, resetCache } = useFetchKeys(search)
const pageRef = useRef(0)

const query = useInfiniteQuery({
queryKey: [FETCH_KEYS_QUERY_KEY, search],

initialPageParam: 0,
queryFn: async () => {
queryFn: async ({ pageParam: page }) => {
// We should reset the cache when the pagination is reset
if (pageRef.current > page) resetCache()
pageRef.current = page

return await fetchKeys()
},
select: (data) => data,
Expand Down

0 comments on commit aed0c8d

Please sign in to comment.