Read data from a cart
This guide shows you how to read a user's cart.
RequirementsAnchor link to section titled "Requirements"
Step 1: Get a visitor's cartAnchor link to section titled "Step 1: Get a visitor's cart"
cart, created from
createCartHandler, to get a user's cart. You don't need to provide a cart ID because it's already handled by the cart handler.
cart.get() returns a promise. Use Remix's defer so that the cart data is deferred, and streamed to the browser.
Step 2: Server render the content of the cartAnchor link to section titled "Step 2: Server render the content of the cart"
You can get the content of the cart using Remix's
useMatches hook, because you made it available in the root loader. Since the data is deferred, you'll need to wait for the data.