Skip to content

Commit

Permalink
Merge pull request #196 from Kernel360/configure-staletime
Browse files Browse the repository at this point in the history
페이지 기능: staletime 설정
  • Loading branch information
bottlewook authored Feb 20, 2024
2 parents 16b9b19 + 4b104b1 commit 187fb8b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/providers/QueryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ import { useState } from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

const CONFIGURATION_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: CONFIGURATION_TIME,
cacheTime: CONFIGURATION_TIME,
},
},
});
});

return (
<QueryClientProvider client={client}>
Expand Down
10 changes: 9 additions & 1 deletion src/remote/queries/home/useProductList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 187fb8b

Please sign in to comment.