T
TanStack16mo ago
fair-rose

executing enabled false query

export function getAssistantOptions(id: string | null) {
return queryOptions({
queryKey: ['assistant', id],
queryFn: () => console.log('log'),
enabled: false,
})
}
export function getAssistantOptions(id: string | null) {
return queryOptions({
queryKey: ['assistant', id],
queryFn: () => console.log('log'),
enabled: false,
})
}
this still execute and shows 'log' in terminal. Using it with a useSuspense() call
const { data: assistant } = useSuspenseQuery(getAssistantOptions(id))
const { data: assistant } = useSuspenseQuery(getAssistantOptions(id))
5 Replies
fair-rose
fair-roseOP16mo ago
okey just realized its because suspenseQuery. Is there any way to make those queries conditional?
eastern-cyan
eastern-cyan16mo ago
No
stormy-gold
stormy-gold16mo ago
What do you need that for? Note that you don't need enabled for dependent queries when using suspense
fair-rose
fair-roseOP16mo ago
i have a route with an optional param [...id]] and depending if thats coming I want to prefetch & execute the suspenseQuery. I guess its fine if I just move to use useQuery, but what its an unexpected behaviour is to set enabled: false and get the console.log executed anyhow
stormy-gold
stormy-gold16mo ago
render the component that does the query conditionally or switch to useQuery

Did you find this page helpful?