filipstefansson
filipstefansson
CCConvex Community
Created by filipstefansson on 12/15/2023 in #support-community
useQuery local cache
Hi! I'm trying to figure out if there's any local caching with useQuery... I've setup a basic example where I make a query based on an ID in the URL and it looks like it's making a request to the backend every time: https://share.filip.sh/XBbZ2nxm. As you can see, the title is flashing on each route change and I log "log from db", which also happens every time. Frontend:
const thread = useQuery(api.threads.getBasic, {
threadId: props.params.threadId,
});
const thread = useQuery(api.threads.getBasic, {
threadId: props.params.threadId,
});
Backend:
export const getBasic = query({
args: { threadId: v.string() },
handler: async ({ db }, args) => {
const threadId = db.normalizeId("threads", args.threadId);
invariant(threadId, "id not found");

console.log("log from db");
const thread = await db.get(threadId);

return thread;
},
});
export const getBasic = query({
args: { threadId: v.string() },
handler: async ({ db }, args) => {
const threadId = db.normalizeId("threads", args.threadId);
invariant(threadId, "id not found");

console.log("log from db");
const thread = await db.get(threadId);

return thread;
},
});
I found this section in the docs, but it sounds like that's about caching on the server? https://docs.convex.dev/functions/query-functions#caching--reactivity
17 replies