useCart
The useCart hook gives access to the Cart object and helper functions, such as addToItem and removeItem, for applying changes in the cart.
Import
import { useCart } from '@faststore/sdk'
Usage
function Cart () {
  const { items, isValidating } = useCart()
  return (
    <>
      {items.map(item => (
        <div>name: {item.itemOffered.name}</div>
        <div>Price: {item.price}</div>
      ))}
      <a href="/checkout">{isValidating ? 'loading...' : 'Checkout'}</a>
    </>
  )
}
Return
addItem(item: T) => voidDescription
Adds items to the cart.
emptyCart() => voidDescription
Removes all items from the cart.
getItem(id: string) => T | undefinedDescription
Gets a given item from the cart.
idstringDescription
Gets the cart's id.
inCart(id: string) => booleanDescription
Checks if an item is in the cart.
isEmptybooleanDescription
Checks if the cart is empty.
isValidatingbooleanDescription
Returns `true` if the optimistic cart is validating the cart.
itemsItemDescription
Gets the current items in the cart.
removeItem(id: string) => voidDescription
Removes an item from the cart.
setCart(cart: Cart) => voidDescription
Replaces the cart with a new one.
updateItemQuantity(id: string, quantity: number) => voidDescription
Updates the quantity of a given item in the cart.