bill92
bill924w ago

conditional useQuery without input

How to use the enabled option for useQuery that doesn't has an input?
const { isError, error } = trpc.iam.logout.useQuery(undefined, {
enabled: isEnabled,
});
const { isError, error } = trpc.iam.logout.useQuery(undefined, {
enabled: isEnabled,
});
I'm passing undefined and TS is not complaining, only on runtime I get app-index.js:33 Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: [["iam","logout"],{"type":"query"}] How to properly use this feature?
4 Replies
Ahmed Elsakaan
a query is enabled by default, so you don't need enabled: true
Mika
Mika4w ago
I'm a bit late but perhaps you're looking for mutations , not queries. Makes no sense to have a logout as a query. Queries are data loaders (get data) Mutations are actions (do something)
bill92
bill923w ago
I was going to use a mutation, but the mutation is expecting that I pass arguments
BeBoRE
BeBoRE3w ago
Not if you pass undefined just like you did here no?