filipstefanssonF
Convex Community3y ago
16 replies
filipstefansson

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,
});


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;
  },
});


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
Queries are the bread and butter of your backend API. They fetch data from the
Queries | Convex Developer Hub
Was this page helpful?