From ce796a811d656f00875dacdeef71c55b5fde8ec6 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Wed, 21 Feb 2024 01:34:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20stale=20time=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/QueryProvider.tsx | 13 ++++++++++++- src/remote/queries/home/useProductList.ts | 10 +++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/providers/QueryProvider.tsx b/src/providers/QueryProvider.tsx index 6210d8af..1f48c0f7 100644 --- a/src/providers/QueryProvider.tsx +++ b/src/providers/QueryProvider.tsx @@ -5,8 +5,19 @@ import { useState } from 'react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; +const CONFIGURE_TIME = 3 * 60 * 1000; + function QueryProvider({ children }: { children: React.ReactNode }) { - const [client] = useState(() => { return new QueryClient(); }); + const [client] = useState(() => { + return new QueryClient({ + defaultOptions: { + queries: { + staleTime: CONFIGURE_TIME, + cacheTime: CONFIGURE_TIME, + }, + }, + }); + }); return ( diff --git a/src/remote/queries/home/useProductList.ts b/src/remote/queries/home/useProductList.ts index 68f5bba4..e0771d2f 100644 --- a/src/remote/queries/home/useProductList.ts +++ b/src/remote/queries/home/useProductList.ts @@ -5,12 +5,20 @@ import { useInfiniteQuery } from '@tanstack/react-query'; import { HomeSortType } from '@components/home/filer-group/types/filterGroup.type'; import { getProductList } from '@remote/api/requests/home/home.get.api'; +const PAGE_SIZE = 10; + function useProductList(sortType: HomeSortType = 'recent-order') { const { data: productList, isLoading, fetchNextPage, isFetching, hasNextPage = false, } = useInfiniteQuery({ queryKey: ['productList', sortType], - queryFn: ({ pageParam = 0 }) => { return getProductList(Number(pageParam), 10, sortType); }, + queryFn: ({ pageParam = 0 }) => { + return getProductList( + Number(pageParam), + PAGE_SIZE, + sortType, + ); + }, getNextPageParam: (lastPage) => { return ( lastPage.value.last