T
TanStack•4y ago
correct-apricot

why queryCache state status is loading?

Hi i am a student learning react query now first my english writing is bad.. here is my question I used useQuery in A component to get some url, and I want use this url in B component so i use queryClient.getQueryCache().find('queryKey') and it worked! , but when i reload page, this data (getQueryCache) turn undefined so i check console.log and when i after reload query still exist but query's status is loading, i can't understand... how can i used this data when i reload page
No description
5 Replies
correct-apricot
correct-apricotOP•4y ago
No description
constant-blue
constant-blue•4y ago
the react-query cache lives in memory and is gone after a page reload. If you want persistent caching, have a look at the persisters.
constant-blue
constant-blue•4y ago
Also: instead of using queryClient.getQueryCache().find() in componentB, it is usually better to just call useQuery there again. Have a read: https://tkdodo.eu/blog/react-query-as-a-state-manager
React Query as a State Manager
Everything you need to know to make React Query your single source of truth state manager for your async state
correct-apricot
correct-apricotOP•4y ago
Omg!!! Thank you sir!! Sir! can i ask more questions? I guess there's something I'm missing when i reload my pages everytime i used useQuery in A component If so, isn't react-query cache newly added to the memory? and i checked console.log new cache data but when i used getQueryCache, cache data(value?) is undefined 🥲
constant-blue
constant-blue•4y ago
probably the value is not yet in the cache when you try to read from it. That's why I suggested useQuery. In none of our examples, we use getQueryCache().find to read a value during rendering ...

Did you find this page helpful?