Skip to content

Commit

Permalink
πŸ“¦ Chore: ν™•μž₯자 .js둜 λ³€κ²½
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-paik committed Nov 26, 2023
1 parent cbecf03 commit 374030f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/hook/useInfiniteDataQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useInfiniteQuery } from 'react-query';

export default function useInfiniteDataQuery(queryKey, queryFn, config) {
let accountname;

if (typeof queryKey === 'object') {
accountname = queryKey[1]?.accountname || queryKey[1];
}

const { data, fetchNextPage, isLoading, isFetching, hasNextPage } = useInfiniteQuery(
queryKey,
({ pageParam = { skip: 0 } }) => {
const queryParam = { accountname: accountname, skip: pageParam.skip };
return queryFn(queryParam);
},
{
getNextPageParam: (lastPage, allPages) => {
const nextPage = allPages.length > 0 ? allPages.length * config.limit : 0;
return lastPage.data.length < config.limit ? undefined : { skip: nextPage };
},
...config,
},
);

return { data, fetchNextPage, isLoading, isFetching, hasNextPage };
}

0 comments on commit 374030f

Please sign in to comment.