T
TanStack2y ago
wise-white

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
wise-white
wise-whiteOP2y ago
server
No description
wise-white
wise-whiteOP2y ago
client
No description
wise-white
wise-whiteOP2y ago
cartInitialData (check payment_sessions attribute)
No description
wise-white
wise-whiteOP2y ago
data or cart state from react-query
No description
wise-white
wise-whiteOP2y ago
behaviour: react query ignores my initialData and uses cache instead expected: when i pass initalData i want cache to be overwritten
other-emerald
other-emerald2y ago
Hi @Yandex , I can help u. Is that a paid work?
wise-white
wise-whiteOP2y ago
i read through documentation found the issue but to answer the question it's for company i am working in
stormy-gold
stormy-gold2y 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
wise-white
wise-whiteOP2y 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
stormy-gold2y ago
What overwrites what? I don't understand the question...
equal-aqua
equal-aqua2y ago
@Yandex did you ever figure this out? I'm struggling with the same issue
wise-white
wise-whiteOP2y ago
No description
wise-white
wise-whiteOP2y ago
this server and in the client query key will be available immediately

Did you find this page helpful?