T
TanStack2y ago
absent-sapphire

Using prefetchInfiniteQuery with a fn that takes multiple params

I'm currently facing an issue when trying to prefetch
export async function getServerSideProps() {
const queryClient = new QueryClient();

await queryClient.prefetchInfiniteQuery({
queryKey: ['variants'],
queryFn: async () => {
const accessToken = await getToken();
return getVariants({ accessToken });
},
initialPageParam: 1,
});

return {
props: {
dehydratedState: dehydrate(queryClient),
},
};
}
export async function getServerSideProps() {
const queryClient = new QueryClient();

await queryClient.prefetchInfiniteQuery({
queryKey: ['variants'],
queryFn: async () => {
const accessToken = await getToken();
return getVariants({ accessToken });
},
initialPageParam: 1,
});

return {
props: {
dehydratedState: dehydrate(queryClient),
},
};
}
function MyPage () {
const { data, fetchNextPage } = useInfiniteQuery({
queryKey: ['variants'],
initialPageParam: 1,
getNextPageParam: (lastPage) => lastPage.nextPage,
})
function MyPage () {
const { data, fetchNextPage } = useInfiniteQuery({
queryKey: ['variants'],
initialPageParam: 1,
getNextPageParam: (lastPage) => lastPage.nextPage,
})
the function getVariants takes a token argument and an optional page argument that defaults to 1. What would be the correct approach to make the infiniteQuery work?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?