T
TanStack9mo ago
xenial-black

QueryClient shows my cache is being updated during my mutation. However the component isn't updating

Like my title says, I did some stack refactoring that seemed to be unrelated to this but now my useQuery hook doesn't seem to be updating with the new value. Can anyone spot anything wrong with my pattern here? My log on line 48 (picture 1) is showing my query is in fact being updated like I would expect, but I don't see the new data in my component (picture 2)
No description
No description
7 Replies
extended-yellow
extended-yellow9mo ago
Try await queryClient.invalidateQueries(...) Although, you're setting the query data for that same queryKey? It should only be setQueryData or invalidateQueries, not both
xenial-black
xenial-blackOP9mo ago
Thanks for looking. Gotcha, yeah I added that invalidateQueries trying to get it to work. But I just also tried to await it and also not using invalidateQueries, but still no luck.
extended-yellow
extended-yellow9mo ago
Sometimes it's weird IDE preferences, but are you actually incrementing data.id as +data.id or is that just a diff thing
xenial-black
xenial-blackOP9mo ago
that's unary operator I was wondering if it was a data type issue so I was converting all the ids to numbers, but I still have the same issue if I remove them all
No description
extended-yellow
extended-yellow9mo ago
Hard to help with a screenshot of code. I'd check the dev tools to see if your query cache entries look right or make a minimal reproduction on codesandbox/stackblitz
xenial-black
xenial-blackOP9mo ago
10-4. It's a react native project and I haven't even tried messing with query dev tools, but that's a good idea. I'll try to get that setup and dig around thanks
optimistic-gold
optimistic-gold9mo ago
Make sure you're not accidentally mutating old !

Did you find this page helpful?