bill92
bill928mo 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
Ahmed Elsakaan8mo ago
a query is enabled by default, so you don't need enabled: true
Mika
Mika8mo 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
bill92OP7mo ago
I was going to use a mutation, but the mutation is expecting that I pass arguments
BeBoRE
BeBoRE7mo ago
Not if you pass undefined just like you did here no?

Did you find this page helpful?