T
TanStack16mo ago
eastern-cyan

how to update the querry data if any mutation occurred

I have fetch all post from backend with react query. Mapping over the data array which react query provide i have render all post. Now lets say I have LIKE button on each post , if a user like any post how should I update the data state? I don’t want to refetch again. What could be the good of doing this. Does invalidating the query make fetch again?
2 Replies
extended-yellow
extended-yellow16mo ago
Updates from Mutation Responses | TanStack Query React 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...
eastern-cyan
eastern-cyanOP16mo ago
I was looking for this only. Thank you sir

Did you find this page helpful?