use-shopping-cart logouse-shopping-cart
Components

DebugCart

If you ever need to quickly see the properties and values that useShoppingCart() has at a given moment, you can use the DebugCart component. It will display a table of all of the properties—not methods—and let you log any objects to the console.

When using this component, you still must have <CartProvider> wrapped around your application. See the documentation for CartProvider if you don't know how to do that.

import { DebugCart } from 'use-shopping-cart'

export function App() {
  return (
    <>
      <p>This is an example of what the DebugCart component looks like.</p>
      <DebugCart />
    </>
  )
}

Without any style modifications, <DebugCart /> will present more like it does in the following screenshot. It uses fixed positioning by default.

The table resides in the top right of the page via fixed positioning and there aren't any borders around the table elements.

Debugging Tips

If you'd rather not render a component, inspect any component that calls useShoppingCart() in React DevTools: the cart state shows up under its "SyncExternalStore" hook. You can also log every change with useShoppingCart selectors or, outside React, with cart.subscribe.

On this page

Shopping Cart

Your cart is empty

Try the interactive demos on the docs pages!