T
TanStack2y ago
equal-jade

React Query not respecting initialData when there is cache

I have a cart state stored in the cache with the key "cart." When I try to fetch cart information on the server and send it to the client using initialData, the server's data is not replacing the existing cache. Is there a way to make initialData overwrite the cache?
No description
13 Replies
equal-jade
equal-jadeOP2y ago
server
No description
equal-jade
equal-jadeOP2y ago
client
No description
equal-jade
equal-jadeOP2y ago
cartInitialData (check payment_sessions attribute)
No description
equal-jade
equal-jadeOP2y ago
data or cart state from react-query
No description
equal-jade
equal-jadeOP2y ago
behaviour: react query ignores my initialData and uses cache instead expected: when i pass initalData i want cache to be overwritten
metropolitan-bronze
metropolitan-bronze2y ago
Hi @Yandex , I can help u. Is that a paid work?
equal-jade
equal-jadeOP2y ago
i read through documentation found the issue but to answer the question it's for company i am working in
automatic-azure
automatic-azure2y ago
expected: when i pass initalData i want cache to be overwritten
no, that's not how initialData works. it only does something when there is no data yet hence the word initial take a look at hydration - that can also overwrite
equal-jade
equal-jadeOP2y ago
ya i did thanks small question tho when i think it overwrites query client meaning i will loose cache of previously locally stored stuff right ? because in documentation what i understood was i can share ssr query client between server side stuff
automatic-azure
automatic-azure2y ago
What overwrites what? I don't understand the question...
flat-fuchsia
flat-fuchsia2y ago
@Yandex did you ever figure this out? I'm struggling with the same issue
equal-jade
equal-jadeOP2y ago
No description
equal-jade
equal-jadeOP2y ago
this server and in the client query key will be available immediately

Did you find this page helpful?