Sorin
Sorin2mo ago

Query cache usage question

I am using React with convex and the query cache from helpers. If I add useQuery(api.todos.listTodos) in multiple components in the same page, will this generate one query for each mount (as in multiple queries to this function in the same page) or is it using a global cache and call the query function just once? I am coming from TenStack Query that reuses the active query across components and i cn;t find specific about this behaviour in useQuery from convex. Thanks
12 Replies
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
ian
ian2mo ago
The query will be shared and the client will only have one subscription. This is the case without the cashing helpers as well.
Sorin
SorinOP2mo ago
thanks! Is there a pattern to catch error in the useQuery scenario?
erquhart
erquhart2mo ago
Error Handling | Convex Developer Hub
Handle errors in Convex queries, mutations, and actions
Sorin
SorinOP2mo ago
10x! somehow i stayed a bit to long on the happy ppath and didn;t got to read this part!
ian
ian2mo ago
GitHub
convex-helpers/packages/convex-helpers/README.md at main · get-con...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
Sorin
SorinOP2mo ago
this is what i was looking for! I was going towards the adapter for ten stack but i want to explore all the convex stuff in this project I run. The use case are composed kooks where i need to treat erorrs separately. i'll update with useQueryWithStatus Thanks again. i went trough helpers twice, but due to the amount of stuff each time i kind of focused on what was "burning" at that time. It feels that helpers is more then just a few random things. I feel like it deserves a place in the official docs.
erquhart
erquhart2mo ago
If you're using tanstack, you probably want this: https://docs.convex.dev/client/tanstack-query
Convex with TanStack Query | Convex Developer Hub
TanStack Query is an excellent, popular
ian
ian2mo ago
I agree! Hoping to add more to the docs soon
Sorin
SorinOP2mo ago
I saw that one, but if you guys manage the local caching, i felt that another caching layer on top was not my cup of tea. Until now, I will say that thing went super smooth. i am writing a complex realtime canvas and query invalidation was becoming a nightmare! Do you see any advantages of using tenstack over the provided? (with caching, from helpers)? In my mind i only see the local dev tool overlay as a nice thing to have
erquhart
erquhart2mo ago
Convex still manages the cache there - it’s a convex version of tanstack query, so it doesn’t introduce any conflicts. That said, I completely misread your messages and thought you were integrating with Tanstack, but you’re not, so Ian’s recommendation is the one to go with.
Sorin
SorinOP2mo ago
ok. i won't drag it any longer. i feel I have to say this: Great job on the product guys! I was using lambda+py+api gw (back when py was cool), then aws appsync trough amplify, and now convex checks 95% of the boxes. The only thing I miss is a IAM Role for the actions so we can extend without stored credentials into AWS. That is my catch all safety net.

Did you find this page helpful?