T
TanStack•2y ago
absent-sapphire

useInfiniteQuery & Types

Hello! I think i'll go crazy since I can't understand how to type this Hook. I've tried to do the same with useQuery which works good but in the in the case of useInfiniteQuery, I can't grasp it. Can someone help? 🙂 import type { InfiniteData, QueryFunctionContext, UseInfiniteQueryOptions, UseInfiniteQueryResult } from "@tanstack/react-query"; import { useInfiniteQuery } from "@tanstack/react-query"; import { getProjectPagination } from "../endpoints/project"; import { AsyncReturnType } from "type-fest"; import { ProjectPagination } from "../types"; type QueryResponse = AsyncReturnType<typeof getProjectPagination>; type QueryResult = UseInfiniteQueryResult<QueryResponse>; export default function useProjectPagination( offset: number): QueryResponse { return useInfiniteQuery<ProjectPagination>({ queryKey: ["offset_pageSize", offset], queryFn: getProjectPagination({ pageParam: offset }); initialPageParam: 0, getNextPageParam: (lastPage) => { if (!lastPage.hasMore) { return null; } return lastPage.previousOffset && lastPage.previousOffset + offset; } }); }
1 Reply
unwilling-turquoise
unwilling-turquoise•2y ago
as with everything - with type inference

Did you find this page helpful?