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
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!
The query will be shared and the client will only have one subscription. This is the case without the cashing helpers as well.
thanks!
Is there a pattern to catch error in the useQuery scenario?
You would generally use error boundaries: https://docs.convex.dev/functions/error-handling/#errors-in-queries
Error Handling | Convex Developer Hub
Handle errors in Convex queries, mutations, and actions
10x! somehow i stayed a bit to long on the happy ppath and didn;t got to read this part!
Also there's a
useQuery
that returns the error: https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/README.md#richer-usequeryGitHub
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
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.
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
I agree! Hoping to add more to the docs soon
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
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.
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.