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
equal-jadeOP•2y ago
server

equal-jadeOP•2y ago
client

equal-jadeOP•2y ago
cartInitialData (check payment_sessions attribute)

equal-jadeOP•2y ago
data or cart state from react-query

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

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