More corrections for useCart

This commit is contained in:
Luis Alvarez
2021-01-28 18:34:44 -05:00
parent 3e27b80658
commit 59a4535f0e
4 changed files with 17 additions and 18 deletions

View File

@@ -191,13 +191,11 @@ Returns the current cart data for use
...
import useCart from '@bigcommerce/storefront-data-hooks/cart/use-cart'
const countItem = (count: number, item: any) => count + item.quantity
const countItems = (count: number, items: any[]) =>
items.reduce(countItem, count)
const countItem = (count: number, item: LineItem) => count + item.quantity
const CartNumber = () => {
const { data } = useCart()
const itemsCount = Object.values(data?.line_items ?? {}).reduce(countItems, 0)
const itemsCount = data?.lineItems.reduce(countItem, 0) ?? 0
return itemsCount > 0 ? <span>{itemsCount}</span> : null
}

View File

@@ -79,9 +79,6 @@ interface BaseProductVariant {
sku: string
// The product variants title, or the product's name.
name: string
// Image associated with the product variant. Falls back to the product image
// if no image is available.
image: Image
// Whether a customer needs to provide a shipping address when placing
// an order for the product variant.
requiresShipping: boolean
@@ -89,6 +86,9 @@ interface BaseProductVariant {
price: number
// Product variants price, as quoted by the manufacturer/distributor.
listPrice: number
// Image associated with the product variant. Falls back to the product image
// if no image is available.
image?: Image
// Indicates whether this product variant is in stock.
isInStock?: boolean
// Indicates if the product variant is available for sale.