SW
SW2mo ago

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,
});
}
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?
3 Replies
Convex Bot
Convex Bot2mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
ballingt
ballingt2mo ago
Today you can use "skip" instead of enabled, see https://github.com/get-convex/convex-react-query/issues/5 but we should implement enabled, I left that issue open to remind us

Did you find this page helpful?