Preload queries
posva opened this issue · 3 comments
Allowing a query to be preloaded
Requires all the options rather than just the key as otherwise it might not exist
Is preloading a query the same as instantiating the query before user navigation? The key difference should be allowing preloading in user actions (e.g., click, hover, etc.) and in lifecycle hooks. Should we introduce another API, like usePreloadQuery
, specifically for this purpose?
it is about instantiating the query. It doesn't have to be about navigation but it should integrate easily into that too. I'm not sure if a new API is needed yet. The idea is to have:
- A way to ensure the entry (should be good)
- A method that can load the entry and return a promise
So maybe this is just a matter of documentation at this point. Not sure yet
Currently doable with
const queryCache = useQueryCache()
queryCache.setQueryData(['the key'], await fetchData())
Depending on the staleTime
, the data will be fresh and calling refresh()
won't get it again