Shopify / hydrogen-v1

React-based framework for building dynamic, Shopify-powered custom storefronts.
https://shopify.github.io/hydrogen-v1/
MIT License
3.75k stars 326 forks source link

Async hooks in useCart #2420

Open beachstrider opened 1 year ago

beachstrider commented 1 year ago

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.

frandiox commented 1 year ago

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.

lordofthecactus commented 1 year ago

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.

beachstrider commented 1 year ago

Yeah, I tried that way and it brought about useless complexity. Hope it will be supported on v2.

On Tue, Jan 17, 2023 at 3:02 AM Daniel Rios @.***> wrote:

As @frandiox https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/Shopify/hydrogen/issues/2420#issuecomment-1384396095, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALRTRRYNEDYOKCFPTI2TP7TWSWEMFANCNFSM6AAAAAATQWH6XE . You are receiving this because you authored the thread.Message ID: @.***>