Hey, I have a small Problem with TanStackQuery. Th...
# javascript
h
Hey, I have a small Problem with TanStackQuery. The options that expect functions don't work.
Copy code
useQuery<Array<DocumentationElementDto>?, Error, Array<DocumentationElementDto>, QueryKey>(
    options = UseQueryOptions(
        queryKey = DOCUMENTATION_QUERY_KEY.plus(subCategory),
        queryFn = QueryFunction { 
            secureApi(DocumentationEndpoints
                .getDocumentationElement
                .copy(optionalQueryParams = pairListOf("category" to subCategory))
        )},
        refetchOnMount = { _ -> false },
        refetchOnWindowFocus = { _ -> false },
        refetchOnReconnect = { _ -> false },
        refetchInterval = 0,
        refetchIntervalInBackground = false,
    )
)
In this case
Copy code
refetchOnMount = { _ -> false },
refetchOnWindowFocus = { _ -> false },
refetchOnReconnect = { _ -> false },
doesn't work, but these two:
Copy code
refetchInterval = 0,
refetchIntervalInBackground = false,
behave as expected. I also tried
useCallback { _ -> false }
, but it isn't accepted by the compiler.
t
Copy code
// file constant
val NO_REFETCH = { _: Any? -> false } 


refetchOnMount = NO_REFETCH,
refetchOnWindowFocus = NO_REFETCH,
refetchOnReconnect = NO_REFETCH
?
h
I'll try that shortly, but I think I also tested that.
t
If it doesn't work - probably it's TanStack Query issue.
h
Hm, sadly it didn't work, when I switch tabs it executes the query again, and it's also not in the debug view:
Ok, turns out the very first thing
{ _ -> false}
works. It just doesn't show up in the debugger. Other fields had filled functions depicted with this:
{ }
I had two
useQuery
with the same key and I wrongly assumed that with these options the according observer wouldn't update when the underlying
QueryKey
updates. So one observer had the options and the other didn't, but the one that didn't still got the update pushed when the observer with refetch still enabled triggered the refetch. Sorry, that behaviour was kind of unexpected for me.
blob no problem 1