How to change state, when 1 mutation worked, and you need to fetch result with another mutation?
Ecom project.
On pages with catalog list, i have product cards, when i press on "add to cart", i send request to server. After that, i want on cart icon in header counter to appear, showing the number of cart.products.length.
My backend partner says, he can send cart items in response to api/add_to_cart. That is ok, But is there any way to listen to add_to_cart and update state instantly in header?
i try to do this, but sometimes await refetch() works before data is on the server

7 Replies
xenial-black•2y ago
Your mutation should trigger invalidation in onSuccess
exotic-emeraldOP•2y ago
Have checked. It does not work(
exotic-emeraldOP•2y ago

exotic-emeraldOP•2y ago

exotic-emeraldOP•2y ago
When i change smth in cart, i want cart info (GET) to be updated and rendered in component.
I have POST, DELETE and GET for cart
xenial-black•2y ago
Yes. queryClient=useQueryClient()
exotic-emeraldOP•2y ago
It works...Thank you man! So much)