T
TanStack2y ago
exotic-emerald

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
No description
7 Replies
xenial-black
xenial-black2y ago
Your mutation should trigger invalidation in onSuccess
exotic-emerald
exotic-emeraldOP2y ago
Have checked. It does not work(
exotic-emerald
exotic-emeraldOP2y ago
No description
exotic-emerald
exotic-emeraldOP2y ago
No description
exotic-emerald
exotic-emeraldOP2y 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
xenial-black2y ago
Yes. queryClient=useQueryClient()
exotic-emerald
exotic-emeraldOP2y ago
It works...Thank you man! So much)

Did you find this page helpful?