Skip query: best strategy?
Hi, I've been searching the docs and previous posts and I can't find the answer.
What is the best strategy for skipping a query using the api from trpc/react?
let's say as an example, that i have a modal, where I want to fetch some data for it when is opened, and skip it if is closed. With tanStack query you can pas sin the skip token, but when using trpc/reat I can't find the way to pass in the skip token, any ideas?
like: const {data} = api.somEndpoint.someQuery.useQuery({someid}, {skip: true})
2 Replies
https://trpc.io/docs/client/react/useQuery
https://trpc.io/docs/client/react/disabling-queries
It is actually officially documented in trpc.
useQuery() | tRPC
useQuery is the primary hook for data fetching, it works similarly to @tanstack/react-query's useQuery, but with some trpc specific options and additional features like streaming.
Disabling Queries | tRPC
To disable queries, you can pass skipToken as the first argument to useQuery or useInfiniteQuery. This will prevent the query from being executed.
thanks for the links @Xanacas