FuzzymaF
Convex Community6mo ago
32 replies
Fuzzyma

Why isnt `useQuery` returning a cached result right away?

When i use
convex.query(someQuery)
in a loader and in a sub component i use
useQuery(someQuery)
, the query doesn't return a result right away. I would have expected that the value is cached somehow. Isn't that the case? I would love to use loaders to ensure data is there but i don't want to use
useLoaderData()
because I loose the real time capabilities of the one-off-query i request in the loader

Any insights would be appreciated. The docs say

Convex caches query results automatically. If many clients request the same query, with the same arguments, they will receive a cached response.

So I expected an instant result. But its always
undefined
first which leads to flashing of wrong component state
Fetch data from the database with caching and reactivity
Queries | Convex Developer Hub
Was this page helpful?