useQuery single request
I have a query and I have multiple tables that affect it.
What I want is to throw the query once and use it on the client. I can send a request as an http end but what I want is an internal solution.
For example
const data= useQuery(api....) //web socket
const data=useFetchQuery(api....) //http request
We can turn the API from query function to mutation function on the server and use it on the client but this time we give up the backend cache
8 Replies
Convex React | Convex Developer Hub
Convex React is the client library enabling your React application to interact
Thanks. We couldn't find it in the documentation. But as I said for React, an internal hook would be nice for these scenarios.
Did you look at this page but missed it because it was collapsed, or because it was badly named, or did you not look at this page at all (and if so, why, is it hard to find?). We're always looking for feedback!
I see, you want to do this inside a render.
We haven't provided that API as it's usually an anti-pattern. What's the use case for showing a potentially stale result from the DB? You could put the value in state if you don't want it to change.
This article could be helpful:
https://stack.convex.dev/help-my-app-is-overreacting
Help, my app is overreacting!
Reactive backends like Convex make building live-updating apps a cinch, but default behavior might be too reactive for some use cases. Not to worry! L...
My database tables are simply like this:
We show the user 1 product that they can react to by removing the products they like and dislike from all products.
Our problem is that when a new product is added while the user is on the screen, the user's screen changes because the result changes. In fact, we only want the query to be refreshed when the user reacts.
You can think of it like Tinder. That's why we wanted to use the solution I mentioned.
If you have different suggestions, I'd love to hear them.
We also thought about calculating and keeping the products that will be shown to the user in a separate table, but it seemed to us that it would make things even more complicated. Because the user can customize the result set by brand and category.
What is the order in which you want to show the products?
(My intuition tells me that React state or ref is probably what you want. Similar to the article I linked, you can decide when to update the state or ref based on the user liking or disliking)
We have read almost all your blog posts.
useConvex().query will do the trick for now.
Thanks.
you can also use TanStack query and make your
queryFn
do the convex.query
but I agree - holding onto the current product client-side, and explicitly changing that so the product doesn't change underneath sounds like the right call.