datagutt
datagutt3d ago

skipToken combined with the new tanstack query options

I am trying to prefetch the next x pages in a table, but i have some logic to determine whether or not this should happen. I used to use skipToken for this, with the old tanstack query package, and it seemed to sort of working. I tried changing the code to fit the new react query package, but it instead of skipping it now runs the API call without any options.
usePrefetchQuery(
trpc.lead.paginate.queryOptions(
query?.data?.pagination &&
query.data.pagination.page > 1 &&
query.data.pagination.page < query.data.pagination.totalPages
? {
...input,
pagination: { perPage: paginationOptions.perPage, page: query.data.pagination.page - 1 },
}
: skipToken,
),
);
usePrefetchQuery(
trpc.lead.paginate.queryOptions(
query?.data?.pagination &&
query.data.pagination.page > 1 &&
query.data.pagination.page < query.data.pagination.totalPages
? {
...input,
pagination: { perPage: paginationOptions.perPage, page: query.data.pagination.page - 1 },
}
: skipToken,
),
);
2 Replies
datagutt
dataguttOP3d ago
For what its worth i also tried using enabled: false/true as the second arg send to queryOptions
Nick
Nick2d ago
This might be a bug, skipToken should automatically disable the query I believe We do have a test around this but I'll flesh it out a little more Okay I think I've got it, thanks for the report Will be fixed in the next release

Did you find this page helpful?