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?

13 Replies
wise-whiteOP•2y ago
server

wise-whiteOP•2y ago
client

wise-whiteOP•2y ago
cartInitialData (check payment_sessions attribute)

wise-whiteOP•2y ago
data or cart state from react-query

wise-whiteOP•2y ago
behaviour: react query ignores my initialData and uses cache instead
expected: when i pass initalData i want cache to be overwritten
other-emerald•2y ago
Hi @Yandex , I can help u. Is that a paid work?
wise-whiteOP•2y ago
i read through documentation found the issue
but to answer the question it's for company i am working in
stormy-gold•2y ago
expected: when i pass initalData i want cache to be overwrittenno, 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 overwritewise-whiteOP•2y 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
stormy-gold•2y ago
What overwrites what? I don't understand the question...
equal-aqua•2y ago
@Yandex did you ever figure this out?
I'm struggling with the same issue
wise-whiteOP•2y ago

wise-whiteOP•2y ago
this server
and in the client query key will be available immediately