From ce796a811d656f00875dacdeef71c55b5fde8ec6 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Wed, 21 Feb 2024 01:34:24 +0900 Subject: [PATCH 1/2] =?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 From 4b104b1c9be73026a7efa6c85bb927ac7e23d17a Mon Sep 17 00:00:00 2001 From: bottlewook Date: Wed, 21 Feb 2024 01:36:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=EB=8B=A8=EC=96=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/QueryProvider.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/providers/QueryProvider.tsx b/src/providers/QueryProvider.tsx index 1f48c0f7..ad0b29e0 100644 --- a/src/providers/QueryProvider.tsx +++ b/src/providers/QueryProvider.tsx @@ -5,15 +5,15 @@ import { useState } from 'react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; -const CONFIGURE_TIME = 3 * 60 * 1000; +const CONFIGURATION_TIME = 3 * 60 * 1000; function QueryProvider({ children }: { children: React.ReactNode }) { const [client] = useState(() => { return new QueryClient({ defaultOptions: { queries: { - staleTime: CONFIGURE_TIME, - cacheTime: CONFIGURE_TIME, + staleTime: CONFIGURATION_TIME, + cacheTime: CONFIGURATION_TIME, }, }, });