Closed nandorojo closed 4 years ago
I definitely see a use for this hook, but the goal of gatsby-theme-shopify-manager
is to be more of a data theme, and the hook you're describing is more presentation logic. Because storefronts are widely varied in what they need to do within their product forms, I think it would be best to add a useProductForm
into a separate package that consumes gastby-theme-shopify-manager
.
It would be great to have a hook, maybe named
useProductForm
, that lets you manage the current product form on a product page. It would provide the methods and state for tracking which options are selected (and the current variant as a result.)I'm currently working on a Gastby + Shopify store, and I have a hook for this. It's not perfect, but I figured I'd put the code below in case it's helpful.
I'm aware that this code is very messy and wouldn't actually make its way into this library itself. It's heavily inspired by this implementation from the gatsby-shopify-starter. I'm only posting it below to show that this hook can be very useful 😇
It seems like you have a similar implementation in your starter. The ideal approach for this hook would be for it to work with any options a product may have, rather than specific ones like color, etc.
The api would be like this: give us the Shopify product as an argument, and this hook returns the functions needed to update the current variant selected.
Let me know if that makes sense, happy to clarify too.