Shopify / hydrogen-v1

React-based framework for building dynamic, Shopify-powered custom storefronts.

Home Page:https://shopify.github.io/hydrogen-v1/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async hooks in useCart

beachstrider opened this issue · comments

Describe the bug
There must be the way to trigger multiple hooks async.. but there don't seems to be.

To Reproduce
await cartCreate({});
await linesAdd([...]);
await discountCodesUpdate({...});
...

Expected behaviour
Multiple hooks need to be triggered asynchronously.

  • Hydrogen version: 1.6.5
  • Node version: 18.12.1
  • Device details: PC

I don't think you can make the hooks work like this in Hydrogen 1 since they are just React callbacks, but perhaps @lordofthecactus can give more information on this.

The cart is being reworked in Hydrogen 2 and I think it will be more flexible then.

As @frandiox mentioned, in Hydrogen v1 It is not possible at the moment to chain async calls with await. It is possible to do chaining by checking the useCart status and keeping track of which calls have been made.