React Query Defaults

What are the default settings in Wasp for React Query? For example, what is the cache item lifetime. Do I need to create cache keys or is it handled internally? Or is everything just React Query defaults and will reading React Query docs is sufficient? Thanks.
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @neogeofun. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Wasp's useQuery hook is a thin wrapper around the useQuery hook from React Query. One key difference is that Wasp doesn't expect you to supply the cache key - it takes care of it under the hood[^1^]. As for the default settings, Wasp's useQuery hook uses React Query's useQuery hook under the hood. Since React Query comes configured with aggressive but sane default options, you most likely won't have to change those defaults for all Queries[^2^]. If you do need to change the global defaults, you can do so inside the client setup function. Wasp exposes a configureQueryClient hook that lets you configure React Query's QueryClient object[^2^]. Here is an example of how you can do it:
import { configureQueryClient } from 'wasp/client/operations'

export default async function mySetupFunction() {
// ... some setup
configureQueryClient({
defaultOptions: {
queries: {
staleTime: Infinity,
},
},
})
// ... some more setup
}
import { configureQueryClient } from 'wasp/client/operations'

export default async function mySetupFunction() {
// ... some setup
configureQueryClient({
defaultOptions: {
queries: {
staleTime: Infinity,
},
},
})
// ... some more setup
}
So, while reading the React Query docs can be helpful, you should also refer to the Wasp documentation to understand how Wasp has integrated with React Query and any additional features or differences that may exist. ^1^]: [Wasp useQuery Hook (https://wasp-lang.dev/docs/data-model/operations/queries#the-usequery-hook-1) ^2^]: [Overriding Default Behaviour for Queries (https://wasp-lang.dev/docs/project/client-config#overriding-default-behaviour-for-queries) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @neogeofun, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
neogeofun
neogeofun2mo ago
I see, thanks Kapa.
martinsos
martinsos2mo ago
Everything i sjust react query defaults except for cache keys -> we handle those for you. Keep in mind we are still on react-query 4, so you will have to check a bit older docs. We will be moving to newer one this quarter.
Want results from more Discord servers?
Add your server