erquhart
erquhart2y ago

Disable/enable queries: SOLVED (use "skip")

I've seen it mentioned elsewhere that enabled is in the works, and to use useQueries in the meantime. It doesn't seem like useQueries, even if you memoize the args object, actually works this way. It simply never updates when the dynamically excluded query is eventually added.
5 Replies
erquhart
erquhartOP2y ago
Code:
const foo = useQuery(api.app.getFoo, { fooId })
const foosArgs = useMemo(() => {
if (!foo) {
return {}
}
const args = {
foo: {
query: api.app.getFoos,
args: { barId: foo?.barId },
},
}
return args
}, [foo])
const result = useQueries(foosArgs)
const foos = result?.foos
// foos => undefined
const foo = useQuery(api.app.getFoo, { fooId })
const foosArgs = useMemo(() => {
if (!foo) {
return {}
}
const args = {
foo: {
query: api.app.getFoos,
args: { barId: foo?.barId },
},
}
return args
}, [foo])
const result = useQueries(foosArgs)
const foos = result?.foos
// foos => undefined
Man, your model keeps making issues non-blocking. I can just handle undefined args in the convex query, no need for useQueries. Good to go on this, enabled is just a nice to have for me. Like is this maybe even better then enabled? It might be better.
Michal Srb
Michal Srb2y ago
Hey @erquhart this is definitely one way of getting around the limitation, handling it on the server. A way to skip subscribing to the query from the client should be coming soon as well.
giray
giray7mo ago
Hey, is there any development on this?
erquhart
erquhartOP7mo ago
Convex React | Convex Developer Hub
Convex React is the client library enabling your React application to interact
ian
ian7mo ago
Yeah we could probably delete this old thread, now that "skip" has existed for a while?

Did you find this page helpful?