useQuery is not refreshing data after setQueryData
Hello, why below snippet does not refresh useQuery which has queryKey equal to QueryKey.MyItems?
As I log data from getQueryData, I see it's updated.
2 Replies
conscious-sapphire•3y ago
newData.items.splice(itemIndex, 1)updates need to happen in an immutable way https://tanstack.com/query/v4/docs/react/guides/updates-from-mutation-responses#immutability
Updates from Mutation Responses | TanStack Query Docs
When dealing with mutations that update objects on the server, it's common for the new object to be automatically returned in the response of the mutation. Instead of refetching any queries for that item and wasting a network call for data we already have, we can take advantage of the object returned by the mutation function and update the exis...
absent-sapphireOP•3y ago
thank you, that's it