gatsby-shopify-starter
gatsby-shopify-starter copied to clipboard
ProductForm availability check, dependency array bug?
Am I mistaken in thinking the dependency arrays are used incorrectly here. Won't client.product
, variants
, and productVariant
always be different due to a lack of referential equality?
const checkAvailability = useCallback(
productId => {
client.product.fetch(productId).then(fetchedProduct => {
// this checks the currently selected variant for availability
const result = fetchedProduct.variants.filter(
variant => variant.id === productVariant.shopifyId
)
if (result.length > 0) {
setAvailable(result[0].available)
}
})
},
[client.product, productVariant.shopifyId, variants]
)
useEffect(() => {
checkAvailability(product.shopifyId)
}, [productVariant, checkAvailability, product.shopifyId])