Pieter
Pieter2y ago

Query function depends on a variable

In tRPC v10 accessing a specific path is really easy, but because of that I don't control the query key. I'm using tRPC to fetch data based on user input in a search bar. Tanstack Query docs has a specific bit in the detailing that the variable should be included in the query key. What is the tRPC way of handeling this? https://tanstack.com/query/latest/docs/react/guides/query-keys#if-your-query-function-depends-on-a-variable-include-it-in-your-query-key Yes, I can use refetch with the query params in state but this is creating side-effects in my code that I would like to avoid.
Query Keys | TanStack Query Docs
At its core, TanStack Query manages query caching for you based on query keys. Query keys have to be an Array at the top level, and can be as simple as an Array with a single string, or as complex as an array of many strings and nested objects. As long as the query key is serializable, and unique to the query's data, you can use it! Simple Que...
4 Replies
Nick
Nick2y ago
In tRPC the inputs to a query are both the query key and the inputs Could you give an example of the problem? I’m not sure how the state problem is different between vanilla RQ and tRPC RQ
Pieter
PieterOP2y ago
Ah alright, that makes sense then. I could not find that in the docs, is it in there somewhere?
Nick
Nick2y ago
Yes