T
TanStack4y ago
sensitive-blue

How to type pageParam in useInfiniteQuery hook?

I was wondering what's the suggested way to type pageParam in useInfiniteQuery hook? I'm doing it currently this way, but maybe there's a better way:
useInfiniteQuery<FetchStuffResponse>(
['stuff', params],
({ pageParam = 0, signal }) =>
fetchStuff(
{
...params,
offset: pageParam as number,
},
signal
),
{ getNextPageParam: ... }
)
useInfiniteQuery<FetchStuffResponse>(
['stuff', params],
({ pageParam = 0, signal }) =>
fetchStuff(
{
...params,
offset: pageParam as number,
},
signal
),
{ getNextPageParam: ... }
)
3 Replies
quickest-silver
quickest-silver4y ago
you can use the type QueryFunctionContext. First generic is the queryKey, second one is pageParam
({ pageParam = 0, signal }: QueryFunctionContext<QueryKey, number>) =>
({ pageParam = 0, signal }: QueryFunctionContext<QueryKey, number>) =>
quickest-silver
quickest-silver4y ago
GitHub
query/types.ts at 07c96311a50a2aa45f516fa2c153ce68ca8f1a9b · TanSta...
🤖 Powerful asynchronous state management, server-state utilities and data fetching for TS/JS, React, Solid, Svelte and Vue. - query/types.ts at 07c96311a50a2aa45f516fa2c153ce68ca8f1a9b · TanStack/q...
sensitive-blue
sensitive-blueOP4y ago
Thank you so much!

Did you find this page helpful?