Skip to main content
Subscribes to cart state changes. The callback is called whenever the cart is updated.

Parameters

The callback receives the current cart state (or null if not initialized).

Returns

() => void Returns an unsubscribe function to stop listening.

Examples

Basic subscription

Update UI on changes

Unsubscribe when done

Subscribe before init

Multiple subscribers

Conditional logic

Behavior

  • Callback is invoked immediately if cart is already initialized
  • Callback is invoked after every cart mutation (add, update, remove, clear)
  • Multiple subscribers can be active simultaneously
  • Subscribers are stored in a Set (no duplicate callbacks)