SWS
Convex Community14mo ago
4 replies
SW

Disabling query with TanStack Query

I am fetching data using convex query with TanStack query in my React project.
I want to disable running query by condition.
Here is the code.
const { data: fileUrl } = useQuery({
    ...convexQuery(api.tables.files.getFileUrl, {
      fileId: selectedFileId as Id<"files">,
    }),
    enabled: !!selectedFileId,
  });
}

So I want to run query only when select file. But it throws an error to convex log when the page is refreshed because the fileId is not immediately available: ArgumentValidationError: Value does not match validator. Path: .fileId Value: null Validator: v.id("files")

How can I solve it?
Was this page helpful?