How does React Query cache values?

I am working on a Plasmo browser extension that uses WebSockets to communicate with the API. I really need to cache previous responses because I need to keep a 'history' of all values and update them on an event. I know there's tutorials out there, even RQ docs have a blogpost about how to do this(https://tkdodo.eu/blog/using-web-sockets-with-react-query). But it just feels ambiguous to use queryClient.setQueryData() to kind of force RQ to use some data. And even if so, then the most correct way of retrieving data would be to use queryClient.getQueryData(["key"]) instead of something cleaner like useQuery(["key"])(it's requires queryFn). I want to know how RQ does the caching, so I could implement something simpler of my own without overhead for this specific case. Should I try a different caching solution or implement my own? Can I use RQ?
3 Replies
Neto
Neto17mo ago
honestly you can dig into the repo source code
Neto
Neto17mo ago
GitHub
query/packages/query-core/src at main · TanStack/query
🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query. - TanStack/query
notdevkey
notdevkeyOP17mo ago
yeah I left this as a last resort, maybe someone here knows this already and could explain but thanks
Want results from more Discord servers?
Add your server