T
TanStack3y ago
metropolitan-bronze

useInfiniteQuery

hi i wanna use useInfiniteQuery but my server needs pagination in query params, should i include this in my queryKey?
2 Replies
fair-rose
fair-rose3y ago
my example
export const useGetCreatorPosts = (username: string) => {
const { data, isLoading, isError, error, fetchNextPage, isFetchingNextPage } =
useInfiniteQuery({
queryKey: ["creatorPosts-", username],
queryFn: ({ pageParam }) => getCreatorPostsFn(username, pageParam),
getNextPageParam: (lastPage: any, allPages) => {
const nextPage =
lastPage?.data?.creatorPosts?.length === 5
? allPages?.length * 5
: undefined;
return nextPage;
},
staleTime: 3600000,
// retry:false,
// refetchOnMount:false,
// refetchOnWindowFocus:false,
// select: (res) => res,
});

return { data, isLoading, isError, error, fetchNextPage, isFetchingNextPage };
};
export const useGetCreatorPosts = (username: string) => {
const { data, isLoading, isError, error, fetchNextPage, isFetchingNextPage } =
useInfiniteQuery({
queryKey: ["creatorPosts-", username],
queryFn: ({ pageParam }) => getCreatorPostsFn(username, pageParam),
getNextPageParam: (lastPage: any, allPages) => {
const nextPage =
lastPage?.data?.creatorPosts?.length === 5
? allPages?.length * 5
: undefined;
return nextPage;
},
staleTime: 3600000,
// retry:false,
// refetchOnMount:false,
// refetchOnWindowFocus:false,
// select: (res) => res,
});

return { data, isLoading, isError, error, fetchNextPage, isFetchingNextPage };
};
genetic-orange
genetic-orange3y ago
With useInfiniteQuery: no.

Did you find this page helpful?