hocino
hocino3mo ago

Re execute query with React when parameter change

Hi everyone, I use useQuery with react to execute my query but one query's parameter depends from a select tag, How can I reexecute my query when the selected value change. I'm pretty sure I saw something to do that on discord or stack.convex, I didn't retrieve it. Thank for your help
5 Replies
Convex Bot
Convex Bot3mo 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
ian3mo ago
The default behavior of useQuery is that it will re-execute when the parameters change, or the underlying data changes. So this happens by default. If you want to hold onto a cache of previous values so switching between tags doesn't re-fetch each time, you can check out https://stack.convex.dev/magic-caching
Can your database do this? Ep. 1: Magic caching
With Convex's magic query cache, Convex's powerful subscriptions are cached, not merely values. So you get fast, jank-free renders with no cache consi...
hocino
hocinoOP3mo ago
Thank you @ian, I used usePaginatedQuery so I suppose this is why I wasn't able to see this behaviour without trigger loadMore(). I gonna to refactor my code. Is it normal usePaginatedQuery not re execute the pagination query when a parameter change ? Thank you
ian
ian3mo ago
those should also be re-executing on parameter changes. have you gone through the tour yet? would be a good place to start if not https://docs.convex.dev/get-started
Welcome to Convex | Convex Developer Hub
Convex is a novel, fun, and extremely productive way to make backends for your
hocino
hocinoOP3mo ago
Yes I went through the tour. I found my mistake an useeffect prevented to see the update. Thenks @ian

Did you find this page helpful?